欢迎访问服务器技术网-www.fuwuqijishu.com

求教vb代码问题

程序设计 fuwuqijishu 2年前 (2022-10-01) 38次浏览 0个评论 扫描二维码

关于一个猜笑脸的代码
书上给了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

喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Warning: error_log(/www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/#log/log-2410.txt): failed to open stream: No such file or directory in /www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/spider.class.php on line 2900