题目:计算机随机生成一个1~100之间的整数(不显示),游戏者输入一个1~100之间的整数,计算机根据猜测结果给出太大、太小或猜中的提示。只允许用户猜5次,用for循环控制猜数次数。
请大神帮我改改看!
Dim x As Integer, y As Integer
Private Sub Command1_Click()
Randomize
x = Int(Rnd * 100) + 1
Text1.Visible = False
Text1.Text = x
End Sub
Private Sub Command2_Click()
y = Val(Text2.Text)
For i = 1 To 5
If x = y Then
Label3.Caption = "恭喜您猜对了!"
Text1.Visible = True
ElseIf x > y Then
Label3.Caption = "太小"
ElseIf x < y Then
Label3.Caption = "太大"
End If
If i = 5 Then
Exit Sub
End If
Next
End Sub
需要用for来控制循环次数
本回答被网友采纳