窗体有Label1与Label2,其Index属性均为0,Caption分别是:"选手"和"票数".command1(0)的visible为False.
上三个控件是为动态生成控件的首控件.
窗体上还有一个command2,发生事件确定输入生成动态控件的个数N,
请问如何去实现可以多次按command2而不会出错,实现不必退出程序都能重新输入N.
Private Sub Command2_Click()
N = Val(InputBox("请输入选票人数"))
For i = 1 To NLoad Label1(i)
Label1(i).Caption = i & "号选手"
Label1(i).Top = Label1(0).Top + 500 * i
Label1(i).Visible = TrueLoad Label2(i)
Label2(i).Caption = "得票数:" & 0
Label2(i).Top = Label2(0).Top + 500 * i
Label2(i).Visible = True
Load Command1(i)
Command1(i).Caption = "选" & i & "号选手"
Command1(i).Top = Command1(0).Top + 500 * i
Command1(i).Visible = True
Next iEnd SubPrivate Sub Command1_Click(Index As Integer)
Label2(Index).Caption = Val(Label2(Index).Caption) + 1
End SubPrivate Sub Command3_Click()
End
End Sub
上三个控件是为动态生成控件的首控件.
窗体上还有一个command2,发生事件确定输入生成动态控件的个数N,
请问如何去实现可以多次按command2而不会出错,实现不必退出程序都能重新输入N.
Private Sub Command2_Click()
N = Val(InputBox("请输入选票人数"))
For i = 1 To NLoad Label1(i)
Label1(i).Caption = i & "号选手"
Label1(i).Top = Label1(0).Top + 500 * i
Label1(i).Visible = TrueLoad Label2(i)
Label2(i).Caption = "得票数:" & 0
Label2(i).Top = Label2(0).Top + 500 * i
Label2(i).Visible = True
Load Command1(i)
Command1(i).Caption = "选" & i & "号选手"
Command1(i).Top = Command1(0).Top + 500 * i
Command1(i).Visible = True
Next iEnd SubPrivate Sub Command1_Click(Index As Integer)
Label2(Index).Caption = Val(Label2(Index).Caption) + 1
End SubPrivate Sub Command3_Click()
End
End Sub
Private Sub Command2_Click()
N = Val(InputBox("请输入选票人数"))UnloadControl Label1
UnloadControl Label2
UnloadControl Command1For i = 1 To NLoad Label1(i)
Label1(i).Caption = i & "号选手"
Label1(i).Top = Label1(0).Top + 500 * i
Label1(i).Visible = TrueLoad Label2(i)
Label2(i).Caption = "得票数:" & 0
Label2(i).Top = Label2(0).Top + 500 * i
Label2(i).Visible = TrueLoad Command1(i)
Command1(i).Caption = "选" & i & "号选手"
Command1(i).Top = Command1(0).Top + 500 * i
Command1(i).Visible = True
Next iEnd SubPrivate Sub Command1_Click(Index As Integer)
Label2(Index).Caption = Val(Label2(Index).Caption) + 1
End SubPrivate Sub Command3_Click()
End
End SubPrivate Sub UnloadControl(ctls)
For i = 1 To ctls.UBound
Unload ctls(i)
Next
End Sub