Vba Excel数组值存储
我目前正在编写一个宏,它是我工作的标签生成器,基本上它有一个组合框,在组合框中可以选择1-4中的一个数字(我们称这个数字框为将来的参考),还有一组复选框和其他组合框用于选择标签选项。在宏中,我有一个数组,它存储每个numberbox的所有信息。每个数字框都有相同的选项可供选择,但选择的选项可能不同Vba Excel数组值存储,vba,excel,excel-2007,excel-2010,Vba,Excel,Excel 2007,Excel 2010,我目前正在编写一个宏,它是我工作的标签生成器,基本上它有一个组合框,在组合框中可以选择1-4中的一个数字(我们称这个数字框为将来的参考),还有一组复选框和其他组合框用于选择标签选项。在宏中,我有一个数组,它存储每个numberbox的所有信息。每个数字框都有相同的选项可供选择,但选择的选项可能不同 EXAMPLE: Numberbox: 1 name label: yes last name label: no gender: yes Numberbox: 2 name label: no
EXAMPLE:
Numberbox: 1
name label: yes
last name label: no
gender: yes
Numberbox: 2
name label: no
last name label: yes
gender: yes
Numberbox: 4
name label: no
last name label: yes
gender: no
我已经说过,当用户在numberbox中选择一个不同的数字时,它会调用一个子程序,该子程序将所有选择的标签存储到一个数组中。在调用此子例程并存储所有信息后,无论用户在“数字”框中选择了什么数字,它都将拉出该信息并自动选择用户已经选择的选项
EXAMPLE:
let's say i start fresh, no info submitted into array yet, i select:
NUMBERBOX: 1
name label: yes
last name label: no
gender: yes
在上面的选择之后,我进入numberbox并选择数字2,所有信息将保存到数组的第一个数组中1(1,等等)。然后它会查看数组ARRAYS1(2,诸如此类),因为我选择了2,检查选择的选项(在本例中为无)并提取信息。但由于我还没有提交任何信息,选项名称标签、姓氏标签和性别将为空,如下所示:
NUMBERBOX: 2
name label:
last name label:
gender:
now lets say i input info into numberbox 2
NUMBERBOX: 2
name label: no
last name label: no
gender: no
NUMBERBOX: 1
name label: yes
last name label: no
gender: yes
^^^^(the same as chosen from the first time).
现在,如果我进入NUMBERBOX并再次选择1,它会将所有信息存储到NUMBERBOX 2的数组中,因此ARRAYS1(2,诸如此类),返回数组以获取NUMBERBOX 1的信息,现在它应该是这样的:
NUMBERBOX: 2
name label:
last name label:
gender:
now lets say i input info into numberbox 2
NUMBERBOX: 2
name label: no
last name label: no
gender: no
NUMBERBOX: 1
name label: yes
last name label: no
gender: yes
^^^^(the same as chosen from the first time).
现在的问题是,我有一个按钮,当点击它时,它会选择一个选项并选中它
q24.value=true
假设此复选框用于名称标签“是”选项,我还有另一个按钮,可以将NUMBERBOX值更改为“2”
它应该调用Private Sub current\u Label\u number\u Change()
并将信息存储到数组中,然后将其更改为2
但出于某些原因,它没有存储信息,出于某些原因,仅当用户自己选择复选框或组合框时,才会存储“我的选项”,使用类似于:q24.value=true的代码不起作用。我不知道为什么,有人请帮忙
谢谢这是存储信息和检索信息的完整代码
Private Sub Current_Bay_Number_Enter()
Dim i As Integer
For i = 0 To 19 Step 1
If Me.Controls("Q" & i).Value = -1 Then
Question_Value(Cu
rrent_Bay_Number.Value - 1, i) = 1
Else
Question_Value(Current_Bay_Number.Value - 1, i) = Me.Controls("Q" & i).Value
End If
Next
For i = 22 To 27 Step 1
If Me.Controls("Q" & i).Value = -1 Then
Question_Value(Current_Bay_Number.Value - 1, i) = 1
Else
Question_Value(Current_Bay_Number.Value - 1, i) = Me.Controls("Q" & i).Value
End If
Next
Call DataEntry
End Sub
“好的,好的,好的”
发布您当前的代码。我已经发布了用于存储和从数组中检索信息的代码作为回答。不过,我自己已经解决了这个问题。我只是太傻了
Private Sub current_bay_number_Change()
Dim i As Integer
For i = 0 To 19 Step 1
Me.Controls("Q" & i).Value = Question_Value(Current_Bay_Number.Value - 1, i)
If Me.Controls("Q" & i).Value = -1 Then
Me.Controls("Q" & i).Value = 1
End If
Next
For i = 22 To 27 Step 1
Me.Controls("Q" & i).Value = Question_Value(Current_Bay_Number.Value - 1, i)
If Me.Controls("Q" & i).Value = -1 Then
Me.Controls("Q" & i).Value = 1
End If
Next
'"SMD-2C FUSE" & "DOUBLE BREAK SWITCH" & "# OF DOORS" combo box is locked
Q15.Locked = True
Q17.Locked = True
End Sub