***************************************************************
2つの配列をDictionary(辞書)に変換する
【引数】KeyAry :1次元配列(Key用)
ItemAry :1次元配列(Item用)
***************************************************************
Public Function fArray_to_Dictionary2(KeyAry As Variant, Optional ItemAry As Variant = Empty) As Scripting.Dictionary
Dim Dic As Scripting.Dictionary
Set Dic = New Scripting.Dictionary
'- 次元数を取得
Dim Dim_Key As Long
Dim Dim_Item As Long
Dim_Key = fArray_DimCount(KeyAry)
Dim_Item = fArray_DimCount(ItemAry)
If Dim_Key = 1 Then
'- 要素情報を取得
Dim Row_Key_L As Long
Dim Row_Key_U As Long
Row_Key_L = LBound(KeyAry, 1)
Row_Key_U = UBound(KeyAry, 1)
'- Item配列が1次元の場合、要素情報を取得しておく
Dim Row_Item_L As Long
Dim Row_Item_U As Long
Row_Item_L = 0
Row_Item_U = -1
If Dim_Item = 1 Then
Row_Item_L = LBound(ItemAry, 1)
Row_Item_U = UBound(ItemAry, 1)
End If
'- 開始位置を取得
Dim i_Item As Long
i_Item = Row_Item_L
Dim i_Key As Long
For i_Key = Row_Key_L To Row_Key_U
If Dic.Exists(KeyAry(i_Key)) = False Then
Dim Item As Variant
Item = Empty
If i_Item <= Row_Item_U Then
Item = ItemAry(i_Item)
End If
Call Dic.Add(KeyAry(i_Key), Item)
End If
'- KeyとItemの位置を同期させておく
i_Item = i_Item + 1
Next
End If
Set fArray_to_Dictionary2 = Dic
Set Dic = Nothing
End Function