① 設計一個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小程序,是猜數字的新手

代碼沒有問題。。
可能是你真的沒有猜對隨機產生的數