① 设计一个VB猜数字游戏程序

啥叫用菜单开始程序?是开始游戏哇?就跟蜘蛛纸牌扫雷一样哇?用户是把自己猜的数放在textbox里,还是inputbox?以上均为疑问句……

② vb猜数字游戏程序编写

先说程序的错误
1.把Int((10 * Rnd) + 1)放到CMD1里
也就是每点一次产生的数都不一样
怎么猜啊

2.没加计数器,不能判断出猜了几次

所以修改后的代码
加一个按钮CMD2,用来重新产生随机数,进行新一轮猜数

Dim x As Integer, y As Integer, z As Integer
Dim cishu As Integer '保存次数的变量
Private Sub Command1_Click()
’如果猜3次了就告诉数字是多少,然后退出,等待点击CMD2重新进行
If cishu = 3 Then Msgbox "已经猜3次了,这个数是" & x: Exit Sub
y = Val(Text1.Text)

If Text1.Text = "" Or Not IsNumeric(Text1.Text) Then
MsgBox "输入有误!请重新输入数字", 48
Text1.Text = ""
Text1.SetFocus
Exit Sub

End If

cishu = cishu + 1
Select Case x - y
Case Is < 0
z = MsgBox("你猜数大了,请重猜。注意:你只有三次机会", 48 + 1)
Text1.Text = ""
Text1.SetFocus
Case Is > 0
z = MsgBox("你猜数小了,请重猜。注意:你只有三次机会", 48 + 1)
Text1.Text = ""
Text1.SetFocus
Case Else
z = MsgBox("恭喜你猜中了!", 1)
End Select

End Sub

Private Sub Command2_Click()
‘点CMD2时重新开始,所以重置次数为0,重新产生一个随机数
cishu = 0
Randomize Timer
x = Int((Rnd * 10) + 1)
End Sub

Private Sub Form_Load()
’程序开始时自动重置一次,可以省去,如果省去的话开始前需要点CMD2开始游戏
cishu = 0
Randomize Timer
x = Int((Rnd * 10) + 1)
End Sub

③ VB求猜数游戏的编写代码

添加两个按钮(一个是 “生成一个数”,另一个是 “猜测”),一个label1,一个text1
所有 代码如下:
Dim a As Integer, b As Integer
Private Sub Command1_Click() '生成一个数 按钮
Label1.Visible = False 'label1 不可见
Randomize
a = Int(4 * Rnd + 1) '随机生成数字范围1~4,自己设置
Label1.Caption = a
End Sub

Private Sub Command2_Click() '猜测 按钮
b = Val(Text1.Text)
If CStr(a) = CStr(b) Then
respose = MsgBox("你答对了", vbOKOnly, "提示") '对话框只有确定按钮
Label1.Visible = True
Else
respose = MsgBox("你错了", vbRetryCancel, "提示") '对话框有重试和取消按钮
If respose = vbRetry Then
Text1.SetFocus
Text1.text =""
Else
Label1.Visible = True
End If
End If
End Sub

④ vb猜数字小游戏代码

Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Randomize
j = Fix(Rnd * 99) + 1
'Print j
Do
k = InputBox("请输入你猜的数:", "提示", 0)
If k > j Then
Print "大了"
ElseIf k < j Then
Print "小了"
Else
Print "猜对了"
End If
i = i + 1
If i > 150 Then Exit Do
Loop Until j = k
End Sub

⑤ VB猜数字游戏程序代码

OptionExplicit

PrivateSubCommand1_Click()
OnErrorResumeNext
DimIAsInteger
I=MsgBox("下面游戏开始,你准备好了吗?",vbYesNo)
IfI=6ThenFrame1.Visible=True:Text1=""ElseFrame1.Visible=False
Text1.SetFocus
Randomize(Timer)
Text2=Int(Rnd()*10)+1
Text3=0
EndSub

PrivateSubCommand2_Click()
End
EndSub

PrivateSubForm_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
EndSub

PrivateSubText1_KeyPress(KeyAsciiAsInteger)
If(KeyAscii<48OrKeyAscii>57)AndKeyAscii<>13ThenKeyAscii=0
IfKeyAscii=13Then
IfText1<>""ThenJysz
EndIf
EndSub

PrivateFunctionJysz()AsBoolean
Text3=Val(Text3)+1
IfVal(Text1)=Val(Text2)Then
MsgBox"猜对了,你真棒"&Chr(13)&Chr(10)&"请猜下一个……"
Command1_Click
ElseIfVal(Text1)>Val(Text2)Then
MsgBox"猜大了。"
Else
MsgBox"猜小了。"
EndIf
Text1=""
IfVal(Text3)>=3Then
MsgBox"呵呵,没猜对!正确的答案是"&Text2&"。别气馁,再来!"
Command1_Click
EndIf
EndFunction
具体程序已经发到你的邮箱[email protected]
更多代码请参阅我的博客http://hi..com/zgmg/blog

⑥ VB建立一个“猜数程序”。

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

⑦ VB的猜数小游戏

这是界面布局,当然,你可以弄好看一些!代码如下:Dim i As Integer, j As Integer
Private Sub Timer1_Timer()
i = Val(Rnd * 100) + 1
j = Val(Rnd * 100) + 1
Text1.Text = Str(i)
Text2.Text = Str(j)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = False
If i < j Then
Text3.Text = "很遗憾,你猜错了"
Else
Text3.Text = "恭喜,你猜对了"
End If
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True
Timer1.Interval = 10
Text1.Visible = True'滚动显示
Text2.Visible = True'同上
Text3.Text = ""
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
If i > j Then
Text3.Text = "很遗憾,你猜错了"
Else
Text3.Text = "恭喜,你猜对了"
End If
End Sub

⑧ 帮我用vb编写一个猜数字的小游戏,数字1到100,程序语言3到5行即可.

猜数字的小游戏:前提,随机数在你猜中之前不能变
所以要建一个生成新数字按钮command2
如果不想猜又想答案的话还要加一个command3显示答案,这里就显示在text1里
private
sub
command2click()
x=
Int(Rnd()
*
100)
end
sub
Private
Sub
Command1_Click()
if
val(text1.text)>x
then
msgbox
"太大了"
elseif
val(text1.text)
评论
0
0
加载更多

⑨ 用VB做个猜数字的程序

Private Sub Command1_Click()
Dim a As Integer, b As Integer
Randomize
a = Int(Rnd * 10 + 1)
b = InputBox("dd")
If b > a Then
MsgBox "1-" & b
ElseIf a > b Then
MsgBox b & "-10"
Else
Print "right"
End If
Print a
End Sub

⑩ 大家看下我这个vb小程序,是猜数字的新手

代码没有问题。。
可能是你真的没有猜对随机产生的数