动态管理阵列到组合框

时间:2018-04-23 09:30:40

标签: vba excel-vba excel

我正在尝试使我的代码紧凑且易于消耗,现在我遇到了问题。

我有18个可能在未来更多的combox,这些应该用数组初始化:

Array_MyFirstDataSet ...

所以如果我用这个命名模式命名所有的组合框 ComboBox_MyFirstDataSet ...

但我无法弄清楚如何动态分配 ComboBox_MyFirstDataSet.List = Array_MyFirstDataSet

那么我应该将所有数组添加到dictonary而不是将它们保持为独立数组吗?

我的非工作代码如下,

创建数组:

Public Sub initPartslist()

If CPearson.IsArrayEmpty(Settings.Array_Type) Then
    Settings.Array_Type = Split("NA,PRT,ASM,SHEET,WELD PRT,WELD ASS,WELD MRG", ",")
End If

If CPearson.IsArrayEmpty(Settings.Array_SpeedSelect) Then
    Settings.Array_SpeedSelect = Split("NA,Fresing,Dreiing,Vannskjæring,Dreiing og Fresing,Fresing og Dreiing,Sveising,Montering", ",")

End If

在这里,我尝试将数组添加到组合框

Public Sub initComboBox() 'rowNumber As Integer
Dim cCont As control
Dim cName As String

'All members in Frame_MOM
For Each cCont In MOM.Frame_MOM.Controls
    If TypeName(cCont) = "ComboBox" Then
    cName = replace(cCont.name, "ComboBox", "Array")
    cCont.List = Settings.cName
    End If
Next cCont

1 个答案:

答案 0 :(得分:0)

你快到了。如果Settings.cName是数组,它将起作用。像这样:

Dim cName(2, 0 to 2)
cName(0, 0) = "John"
cName(0, 1) = 1982
...
cCont.List = Settings.cName