VB在线急等~~~

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:27:59
我不明白这个按钮为什么要设计为数组呢?就是在下面一段程序里面,它是通过单击Command1增加Option1,option1设计成数组我倒是理解,但Command1为什么也.......
Dim m As Integer
Private Sub Command1_Click(Index As Integer)
If m = 0 Then m = 1
If m > 8 Then Exit Sub
m = m + 1
Load Option1(m)
Option1(0).SetFocus
Option1(m).Top = Option1(m - 1).Top + 400
Option1(m).Visible = True
Option1(m).Caption = "option" & m + 1
End Sub

Private Sub Command2_Click()
If m <= 1 Then Exit Sub
Unload Option1(m)
m = m - 1
Option1(0).SetFocus

End Sub
Private Sub Option1_Click(Index As Integer)
Picture1.BackColor = QBColor(Index + 1)
End Sub
不过只有Private Sub Command1_Click我试过了,运行不了啊~~~就是要Private Sub Command1_Click(Index As Integer)才行了,这些我都是根据教程上做的!

Private Sub Command1_Click(Index As Integer)
这个完全没必要
Private Sub Command1_Click
就可以了

知道了,把这句提前就可以了,
Dim m As Integer
Private Sub Command1_Click()
m = m + 1

If m = 0 Then m = 1
If m > 8 Then Exit Sub
Load Option1(m)
Option1(0).SetFocus
Option1(m).Top = Option1(m - 1).Top + 400
Option1(m).Visible = True
Option1(m).Caption = "option" & m + 1
End Sub

Private Sub Command2_Click()
If m <= 1 Then Exit Sub
Unload Option1(m)
m = m - 1
Option1(0).SetFocus

End Sub
Private Sub Option1_Click(Index As Integer)
Picture1.BackColor = QBColor(Index + 1)
End Sub

解释:
当第一次点按钮时 m = 0,
但你的代码If m = 0 Then m = 1
此时M=1 下面又来个 M = M +1
那么M就=2了,而你的本意是第一次点的话M的值为1

另外 command2里面 If m <= 1 Then Exit Sub
改为 M《=0

我觉得Command1不需要设计成控件数组,在你的代码中也根本没有用到该数组
代码就这么多吗