关于一个猜笑脸的代码
书上给了6个Command控件,但是他的顺序是(0)(1)(2)(3)2 3 我编的时候把顺序改成123456了,如下 但是不能运行~我不知道哪里出错了~~
Private Sub Command1_Click(Index As Integer)
Randomize
a = Int(Rnd * 4)
If a = Index Then
Command1(a).Enabled = False
Label1.Caption = “你猜对了,very good”
For I = 0 To 3
Command1(I).DisabledPicture = LoadPicture(“F:\图片\FACE03.ico”)
Next I
Else
Command1(a).Enabled = False
Label1.Caption = “你猜错了,我在这!”
For I = 0 To 3
Command1(I).DisabledPicture = LoadPicture(“F:\图片\FACE04.ico”)
Next I
End If
End Sub
Private Sub Command2_Click()
For I = 0 To 3
Command(I).Enabled = True
Next I
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Command5_Click()
For I = 0 To 3
Command(I).Enabled = True
Next I
End Sub
Private Sub Command6_Click()
End
End Sub的问题
仔细查看你的代码,你对要求有误解。按你题目的意思,Command1按钮是按钮数组,共4个。另有Command2和Command2两个按钮。
按钮数组生成方法,先在窗体上添加Command1,然后用复制和粘贴法做3次,窗体上共生成4个Command1,其Index属性分别为0 1 2 3。
你代码修改如下:
Option Explicit
Dim a As Integer
Dim i As Byte
Private Sub Command1_Click(Index As Integer)
Randomize
a = Int(Rnd * 4)
If a = Index Then
Command1(a)。
Enabled = False
Label1。Caption = “你猜对了,very good”
For i = 0 To 3
Command1(i)。DisabledPicture = LoadPicture(“F:\图片\FACE03。
ico”)
Next i
Else
Command1(a)。Enabled = False
Label1。Caption = “你猜错了,我在这!”
For i = 0 To 3
Command1(i)。DisabledPicture = LoadPicture(“F:\图片\FACE04。
ico”)
Next i
End If
End Sub
Private Sub Command2_Click()
For i = 0 To 3
Command1(i)。Enabled = True
Next i
End Sub
Private Sub Command3_Click()
End
End Sub
。