求VB的猜数字代码,(直接复制粘贴就能用的)
发布网友
发布时间:2022-04-29 15:01
我来回答
共1个回答
热心网友
时间:2023-10-13 17:46
Public Class Form1
Dim b As Integer
Dim js As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.Button1.Text = "开始" Then
Dim a As Integer = MsgBox("游戏开始你准备好了吗", MsgBoxStyle.YesNo, "提示!")
If a = 6 Then
js = 1
Me.Button1.Text = "确定"
Me.Button2.Text = "返回"
Me.Label2.Text = "我这里有1~10的正整数猜猜是多少"
Me.TextBox1.Visible = True
Randomize()
b = Int(Rnd() * 9 + 1)
Else
Exit Sub
End If
Else
If Me.TextBox1.Text.Trim = "" Or Asc(Me.TextBox1.Text) < 19 Or Asc(Me.TextBox1.Text) > 57 Then
MsgBox("请输入数字")
Exit Sub
Else
If js = 3 Then
MsgBox("对不起,你已经超过3次,请重新开始")
Me.Button1.Text = "开始"
Me.Button2.Text = "退出"
Me.TextBox1.Visible = False
Me.Label2.Text = ""
Else
If Me.TextBox1.Text = b Then
Me.Label2.Text = "你真幸运猜对了"
Me.Button1.Visible = False
Me.Button2.Visible = False
Me.Button3.Visible = True
ElseIf TextBox1.Text > b Then
js += 1
Me.TextBox1.Text = ""
Me.Label2.Text = "你的数据太大了,请重新猜吧,注意只允许猜3次"
ElseIf TextBox1.Text < b Then
js += 1
Me.TextBox1.Text = ""
Me.Label2.Text = "你的数据太小了,请重新猜吧,注意只允许猜3次"
End If
End If
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Button1.Text = "开始"
Me.Button2.Text = "返回"
Me.TextBox1.Text = ""
Me.Button3.Visible = False
Me.TextBox1.Visible = False
Me.Label2.Text = ""
Me.Button1.Visible = True
Me.Button2.Visible = True
End Sub
End Class
你看http://z.baidu.com/question/96056787.html的软件界面 需要2个Label 2个button 1个textbox
参考资料:http://z.baidu.com/question/96056787.html