猜数字游戏代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Dim intnum As Integer
Dim intn As Integer

Private Sub Command1_Click()
Randomize
intnum = Rnd * 100
intn = 1
Command1.Enabled = False
Command2.Enabled = True
End Sub

Private Sub Command2_Click()
Dim intEnter As Integer

If Len(Trim(Text1.Text)) = 0 Then
MsgBox "不能为空!"
Text1.SetFocus
Exit Sub
End If


intEnter = Text1.Text

If intEnter = intnum Then
Label1.Caption = "恭喜您,您答对了!" & " " & "这是您第" & intn & "次猜数字"
Command1.Enabled = True
Command2.Enabled = False
Text1.SetFocus
Text1.Text = ""
ElseIf intEnter > intnum Then
Label1.Caption = "您猜大了" & " " & "这是您第" & intn & "次猜数字"
intn = intn + 1
Else
Label1.Caption = "您猜小了" & " " & "这是您第" & intn & "次猜数字"
intn = intn + 1
End If



End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub

If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

End Sub

相关文档
最新文档