猜数字
控件:
Text1 - 注意将MultiLine属性修改为True
Command1
代码:
Private Sub Command1_Click()
Randomize
Dim Num As Long
Dim RightAnswer As Boolean
Dim InputNum As Long
Text1.Text = \"\"
Num = Int(Rnd * 1000) + 1
RightAnswer = False
Text1.Text = Text1.Text + \"Here's a number between 1 and 1000. Can you guess it?\"
+ vbNewLine
While RightAnswer = False
InputNum = InputBox(\"Enter a number\")
If InputNum = Num Then
Text1.Text = Text1.Text & InputNum & \" \" & \"You guessed it!\" & vbNewLine
RightAnswer = True
ElseIf InputNum < Num Then
Text1.Text = Text1.Text & InputNum & \" \" & \"Too Small\" & vbNewLine
ElseIf InputNum > Num Then
Text1.Text = Text1.Text & InputNum & \" \" & \"Too Large\" & vbNewLine
End If
Wend
End Sub
调试通过,无错误处理