VB哪里错了

[复制链接]
查看11 | 回复3 | 2009-5-2 20:49:05 | 显示全部楼层 |阅读模式
4.
设计一个标签,内容为随机产生的10以内的加减乘法算式,另设计一个文本框,可以输入运算结果,当用户按回车键时,判断运算结果是否正确、文本框内容是否数字,以输出不同的msgbox提示,并根据用户的按键决定是否重做或重新出题,最后设计两个按钮分别实现程序结束和记分功能(可以参照课件上的程序,注意其中要修改的部分)
Option Explicit
Public p#, a#, b#, c#
Private Sub Command1_Click()
a = Int(Rnd * 10 + 1)
b = Int(Rnd * 10 + 1)
c = Int(Rnd * 4 + 1)
Select Case c
Case 1

Label2 = a & "+" & b

p = a + b
Case 2

Label2 = a & "-" & b

p = a - b
Case 3

Label2 = a & "*" & b

p = a * b
Case 4

Label2 = a & "/" & b

p = a / b
End Select
End Sub
Private Sub Command2_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "please input a number", 16, "error"
If Text1.Text = answer Then
Print "correct"
Else
Print "error the answer is"; answer
End If
End If
End Sub

回复

使用道具 举报

千问 | 2009-5-2 20:49:05 | 显示全部楼层
If Not IsNumeric(Text1.Text) Then MsgBox "please input a number", 16, "error" If Text1.Text = answer Then 上面的最后一行的上面应该加一个elseIf Not IsNumeric(Text1.Text) Then MsgBox "please input a number", 16, "error" elseIf Text1.Text = answer Then...
回复

使用道具 举报

千问 | 2009-5-2 20:49:05 | 显示全部楼层
answer 改成P...
回复

使用道具 举报

千问 | 2009-5-2 20:49:05 | 显示全部楼层
If Text1.Text = answer Then Print "correct" Else Print "error the answer is"; answer End If 改为 If val(Text1.Text) = p Then Print "correct" Else Print "error the a...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行