我有一个位移图。 我正接收一系列阵列, 其中包括一个字符串, 在代表 shash {HASH} 的阵列的第一个元素中。 我不知道根据不同的调用结果, 阵列的阵列结构会不同。 数据的例子如下:
[ [ "{HASH}", 1000, ["{HASH}", "A", 100], ["{HASH}", "B", 150], ["{HASH}", "C", 200] ],
[ "{HASH}", 1001, ["{HASH}", "D", 101], ["{HASH}", "E", 151], ["{HASH}", "F", 201] ]
]
散列如下:
{1000}{A}=100
{1000}{B}=150
{1000}{c}=200
{1001}{D}=101
{1001}{E}=151
{1001}{F}=201
我写下了以下函数, 被反复称为输出数组中的条目, 这样很好, 但我需要将它放入一个定义的散列中, 这是它失败的地方, 因为它被反复命名为散列被重置等 :
Public Function ProcessObjOrArray(Obj As Variant, key As String, ByRef hashIn, HashCreated As Boolean) As Variant
Dim sKey As String
Dim i As Integer
Dim objRes As Variant
If HashCreated = False Then
Dim hash
HashCreated = True
Set hash = CreateObject("Scripting.Dictionary")
End If
If IsArray(Obj) Then
For i = 0 To UBound(Obj, 1)
objRes = ProcessObjOrArray(Obj(i), sKey, hash, HashCreated)
If (objRes = "{HASH}") Then
i = i + 1
sKey = Obj(i)
End If
Next i
If key <> "" Then
Debug.Print "Adding {" + key + "}=AllTheStuff"
Set hash.Item(key) = hashIn
Dim a
a = hash.Item(key)("Enabled")
Exit Function
End If
Else
If key <> "" Then
Debug.Print "Adding {" + key + "}=" + CStr(Obj)
hash.Item(key) = Obj
Else
ProcessObjOrArray = Obj
End If
End If
End Function
所传递的天体显然就是上面我定义的阵列。如果有人能聪明地这样做,那将非常感激。