Arrays 使用变量作为模块/数组名称
我的最终目标是加载一个组合框,其中包含来自不同数组(vba编码)的元素。我有8个不同的阵列和6个选项按钮。前2个optionButtons分组以消除4个数组,剩下最后4个分组的optionButtons来确定组合框的实际输入 它的工作原理如下:Arrays 使用变量作为模块/数组名称,arrays,excel,vba,Arrays,Excel,Vba,我的最终目标是加载一个组合框,其中包含来自不同数组(vba编码)的元素。我有8个不同的阵列和6个选项按钮。前2个optionButtons分组以消除4个数组,剩下最后4个分组的optionButtons来确定组合框的实际输入 它的工作原理如下: 'first grouped option buttons maleOptionButton femaleOptionButton 'second grouped option buttons basketballOptionButton footba
'first grouped option buttons
maleOptionButton
femaleOptionButton
'second grouped option buttons
basketballOptionButton
footballOptionButton
soccerOptionButton
hockeyOptionButton
你可以猜到,数组中充满了从事体育运动的学生姓名。因此,当用户单击第一组男性/女性按钮时,单击甚至不起任何作用。。但是,当他们单击“运动”的第二组选项按钮时,它会调用模块中具有“如果”和“如果”的相同子过程,以确定所选按钮的组合
子数组()
我想做的是:
dim i as integer
dim l as integer
dim gender as string
dim sport as string
if inputForm.soccerOptionButton.value = true then
if inputForm.maleOptionButton.value = true then
gender = "male"
sport = "maleSoccerArray"
call male.maleInitArray ' inits the array thats hard coded.
else
gender = "female"
sport = "femaleSoccerArray"
call female.femaleInitArray
Else If...
' the list goes on to assign variables depending on the combo boxes.
' doesn't work, but it beats using this every time
l = UBound(sport) ' Doesn't recognize "sport" as an Array
for i = 1 to l
' .AddItem(gender.sport(i)) will not work as well.
inputForm.studentComboBox.AddItem(gender.sport(i))
next i
似乎是UBound(变量)和AddItem(variable.variable)
不起作用
到目前为止,我发现了一些东西,但没有一件有效。。例如application.run方法和分配实际的“male.maleSoccerArray”方法
任何帮助都将不胜感激。。谢谢请更具体地说明哪个部件不工作。我想最后4行是您尝试填充组合框的地方,但为了提供帮助,请向我们展示maleInitArray和femailInitArray的代码。没问题!我编辑了一下。复制/粘贴在这些系统中不起作用。。hahaI我有点困惑,为什么在使用Excel时要硬编码学生数据。试着把这些数据放在工作表中,看一看。首先假设一个特定的用户选择(例如,男性足球运动员),一旦你有了组合框代码,然后根据用户的选择用不同的学生集填充它。哈哈。。我知道在excel中硬编码数据有点愚蠢。我只是想看看它是否也能这样工作。我可以取出变量,在每个then/else语句中使用循环,它工作得很好。再一次。。看看能不能做到(哈哈。。。不可能,要做到这一点,您需要VBA中不可用的反射。同时
将sport设置为字符串,然后l=UBound(sport)
,如何设置??
dim i as integer
dim l as integer
dim gender as string
dim sport as string
if inputForm.soccerOptionButton.value = true then
if inputForm.maleOptionButton.value = true then
gender = "male"
sport = "maleSoccerArray"
call male.maleInitArray ' inits the array thats hard coded.
else
gender = "female"
sport = "femaleSoccerArray"
call female.femaleInitArray
Else If...
' the list goes on to assign variables depending on the combo boxes.
' doesn't work, but it beats using this every time
l = UBound(sport) ' Doesn't recognize "sport" as an Array
for i = 1 to l
' .AddItem(gender.sport(i)) will not work as well.
inputForm.studentComboBox.AddItem(gender.sport(i))
next i