【问题标题】:How to Create a Dynamic Variable Name for an Array?如何为数组创建动态变量名?
【发布时间】:2015-10-16 09:06:29
【问题描述】:

我有“ComboBox1”,其中包含条目。每次用户选择一个条目时,都会触发以下内容:

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

“填充”函数有以下内容:

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

我想让 "arr" + index 动态化,以便它根据从调用者函数收到的索引调用正确的数组。这个可以吗?

【问题讨论】:

  • 使用数组来保存你的数组...
  • 根据下面的答案,在动态名称中调用元素的语法是什么?例如,arr(index).x 其中 x = 1

标签: arrays vba excel combobox


【解决方案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

【讨论】:

  • 如何称呼一个元素?例如,arr(index).x ??
猜你喜欢
  • 1970-01-01
  • 2021-10-26
  • 2011-10-27
  • 2012-08-02
  • 1970-01-01
  • 2021-12-31
  • 2014-09-02
相关资源
最近更新 更多