VB建立一个“猜数程序”。
建立一个“猜数程序”。单击窗体,产生一个2位的随机正整数。在文本框Text1中输入你猜测的数字,单击按钮Command1在窗体上显示猜测结果:如果你输入的数字比程序生成的...
建立一个“猜数程序”。单击窗体,产生一个2位的随机正整数。在文本框Text1中输入你猜测的数字,单击按钮Command1在窗体上显示猜测结果:如果你输入的数字比程序生成的随机数要大,则显示“大了”;如果比程序生成的随机数要小则“小了”;然后继续输入数字进行猜测。如果猜中,则显示“恭喜你猜中啦!”,并用消息框显示一共猜了几次。
展开
4个回答
展开全部
Dim n As Integer, k As Integer
Private Sub Form_Click()
Randomize
n = Int(Rnd * 90) + 10
End Sub
Private Sub command1_click()
Dim x As Integer
x = Text1.Text
k = k + 1
If x > n Then
Print x; "大了"
ElseIf x < n Then
Print x; "小了"
Else
Print x; "恭喜你猜中了!"
MsgBox "一共猜了" & k & "次"
End If
End Sub
展开全部
Dim x As Integer
Private Sub Command1_Click()
If x < Val(Text1) Then
Label1.Caption = "大了"
ElseIf x > Val(Text1) Then
Label1.Caption = "小了"
Else
Label1.Caption = "恭喜你猜对了"
End If
End Sub
Private Sub Command2_Click()
Form_Load
End Sub
Private Sub Form_Load()
Text1.Text = ""
Label1.Caption = ""
x = Int(Rnd * 91) + 10
End Sub
Private Sub Command1_Click()
If x < Val(Text1) Then
Label1.Caption = "大了"
ElseIf x > Val(Text1) Then
Label1.Caption = "小了"
Else
Label1.Caption = "恭喜你猜对了"
End If
End Sub
Private Sub Command2_Click()
Form_Load
End Sub
Private Sub Form_Load()
Text1.Text = ""
Label1.Caption = ""
x = Int(Rnd * 91) + 10
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim intR As Integer
Dim coun As Integer
Private Sub Command1_Click() ‘猜数
Dim cit As Integer
cit = Val(Text1.Text)
coun = coun + 1
If cit > 99 Or cit < 10 Then
MsgBox "请正确输入两位整数"
ElseIf cit = intR Then
MsgBox "您共猜测" & coun & "次,恭喜您猜中了!"
ElseIf cit < intR Then
MsgBox "猜小了"
ElseIf cit > intR Then
MsgBox "猜大了"
End If
End Sub
Private Sub Command2_Click() ’改变数 继续猜
Form_Load
End Sub
Private Sub Form_Load()
Randomize Timer ‘保证每次随机数不一样
intR = Int(Rnd * 90) + 10 ’两位 10-99随机数
coun = 0
Text1.Text = ""
'MsgBox intR ’测试用,查看随机数
End Sub
Dim coun As Integer
Private Sub Command1_Click() ‘猜数
Dim cit As Integer
cit = Val(Text1.Text)
coun = coun + 1
If cit > 99 Or cit < 10 Then
MsgBox "请正确输入两位整数"
ElseIf cit = intR Then
MsgBox "您共猜测" & coun & "次,恭喜您猜中了!"
ElseIf cit < intR Then
MsgBox "猜小了"
ElseIf cit > intR Then
MsgBox "猜大了"
End If
End Sub
Private Sub Command2_Click() ’改变数 继续猜
Form_Load
End Sub
Private Sub Form_Load()
Randomize Timer ‘保证每次随机数不一样
intR = Int(Rnd * 90) + 10 ’两位 10-99随机数
coun = 0
Text1.Text = ""
'MsgBox intR ’测试用,查看随机数
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim ii As Integer
Private Sub Command1_Click()
ii = ii + 1
n = Int(Rnd * 90 + 10)
Me.Caption = n
If Int(Val(Text1.Text)) > n Then
MsgBox "大了", , "提示"
Else
MsgBox "小了", , "提示"
End If
If Int(Val(Text1.Text)) = n Then
MsgBox ii & "次后猜对了", , "提示"
ii = 0
End If
End Sub
Private Sub Command1_Click()
ii = ii + 1
n = Int(Rnd * 90 + 10)
Me.Caption = n
If Int(Val(Text1.Text)) > n Then
MsgBox "大了", , "提示"
Else
MsgBox "小了", , "提示"
End If
If Int(Val(Text1.Text)) = n Then
MsgBox ii & "次后猜对了", , "提示"
ii = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询