English 中文(简体)
VBA 递增和杂货
原标题:VBA Recursion and hashes

我有一个位移图。 我正接收一系列阵列, 其中包括一个字符串, 在代表 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

所传递的天体显然就是上面我定义的阵列。如果有人能聪明地这样做,那将非常感激。

问题回答

我解决了这个问题,方法是使用一个散列经过和在最后关头经过的, 创建一个新的散列,这是经过的散列的复制件, 然后最后重置经过和设置的散列是关键和值 = 相对于我复制的散列。 这成功地创造了散列的散列 。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签