用VB编写程序设计猜数游戏窗体
展开全部
<pre t="code" l="vb">Dim a As Byte
Dim b As Byte '回车次数
Private Sub Command1_Click()
Randomize
a = Int(Rnd * 100 + 1)
Command1.Enabled = False
b = 0
End Sub<pre t="code" l="vb">Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Command1.Enabled = False Then
If b = 10 Then
Label2.Caption = "运气真差!请重新出题!"
Text1.Enabeld = False
Command1.Enabled = True
Exit Sub
End If
If Val(Text1.Text) = a Then
Command1.Enabled = True
Label2.Caption = "正确"
ElseIf Val(Text1.Text) < a Then
Label2.Caption = "太小"
b = b + 1
ElseIf Val(Text1.Text) > a Then
Label2.Caption = "太大"
b = b + 1
End If
End If
End Sub
Dim b As Byte '回车次数
Private Sub Command1_Click()
Randomize
a = Int(Rnd * 100 + 1)
Command1.Enabled = False
b = 0
End Sub<pre t="code" l="vb">Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Command1.Enabled = False Then
If b = 10 Then
Label2.Caption = "运气真差!请重新出题!"
Text1.Enabeld = False
Command1.Enabled = True
Exit Sub
End If
If Val(Text1.Text) = a Then
Command1.Enabled = True
Label2.Caption = "正确"
ElseIf Val(Text1.Text) < a Then
Label2.Caption = "太小"
b = b + 1
ElseIf Val(Text1.Text) > a Then
Label2.Caption = "太大"
b = b + 1
End If
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询