How to Create a Dynamic Variable Name for an Array?

谁说我不能喝 提交于 2019-12-23 02:17:28

问题


I have "ComboBox1" with entries in it. Every time the user selects an entry, the following is triggered:

Private Sub ComboBox1_Change()
    call populate(ComboBox1.ListIndex)
End Sub

The function "populate" has the following:

Sub populate(index as integer)

    dim arr0, arr1, arr2 ...
        arr0 = Array(...)
        arr1 = Array(...)
        arr2 = Array(...)

    Do While x < Application.CountA("arr" + index)
        ...
    Loop

End Sub

I want to make "arr" + index dynamic so it calls the proper array based on the index recevied from the caller function. Can this be done?


回答1:


Sub populate(index as integer)

    dim arr(0 to 2)
        arr(0) = Array(...)
        arr(1) = Array(...)
        arr(2) = Array(...)

    Do While x < Application.CountA(arr(index))
        ...
    Loop

End Sub


来源:https://stackoverflow.com/questions/31631761/how-to-create-a-dynamic-variable-name-for-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!