VB猜数字游戏程序代码

2025-03-12 17:49:11
推荐回答(2个)
回答1:

Option Explicit

Private Sub Command1_Click()
On Error Resume Next
Dim I As Integer
I = MsgBox("下面游戏开始,你准备好了吗?", vbYesNo)
If I = 6 Then Frame1.Visible = True: Text1 = "" Else Frame1.Visible = False
Text1.SetFocus
Randomize (Timer)
Text2 = Int(Rnd() * 10) + 1
Text3 = 0
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Me.Height = 5000
Me.Width = 10500
Me.BorderStyle = 1
Me.Caption = "猜数游戏"
Label1.Left = 0
Label1.Top = 1000
Label1.Caption = "欢迎进入猜数游戏"
Label1.FontName = "楷体_GB2312"
Label1.ForeColor = &H80FF&
Label1.FontSize = 48
Command1.Caption = "开始"
'Command1.Default = True
Command2.Caption = "退出"
Command2.Cancel = True
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 13 Then KeyAscii = 0
If KeyAscii = 13 Then
  If Text1 <> "" Then Jysz
End If
End Sub

Private Function Jysz() As Boolean
  Text3 = Val(Text3) + 1
  If Val(Text1) = Val(Text2) Then
    MsgBox "猜对了,你真棒" & Chr(13) & Chr(10) & "请猜下一个……"
    Command1_Click
  ElseIf Val(Text1) > Val(Text2) Then
    MsgBox "猜大了。"
  Else
    MsgBox "猜小了。"
  End If
  Text1 = ""
  If Val(Text3) >= 3 Then
  MsgBox "呵呵,没猜对!正确的答案是" & Text2 & "。别气馁,再来!"
  Command1_Click
  End If
End Function
具体程序已经发到你的邮箱songxing_cool@yahoo.com.cn
更多代码请参阅我的博客http://hi.baidu.com/zgmg/blog

回答2:

邮件投递成功
收件人
投递状态
时间
lvyang900626@sina.com
已投递到对方服务器
2009年10月19日(星期一)
下午4:50