小张设计了一个“加减运算练习”VB程序。界面如下图所示。单击“出题”Command1按钮显示两个运算数和运算符号,并计数。在文本框Text1中输入计算结果后单击“判断”按钮Command2,如果计算结果正确,则得分加10分,直至完成10题测试。VB程序如下,但加下划线处代码有错,请改正。Dim n,s As Integer 'n为试题计数器,s为得分
Dim a, b As Integer 'a,b 为两个运算数
Dim c As String 'c为运算符:"+ "表示加法,"-"表示减法
Private Sub Form_Load()
n = 0:
s = 0
End Sub
Private Sub Command1_Click() ‘出题按钮
Randomize
n = n + 1
If n < 11 Then
Label1.Caption = "No:" + Str(n)
a = Int(Rnd * 100) 'a,b为运算数,且要求a不小于b
b = Int(Rnd * 100)
If {#blank#}1{#/blank#}Then t = a: a = b: b = t '(1)
If Rnd > 0.5 Then c = "+" Else{#blank#}2{#/blank#} '(2)
Label5.Caption = Str(a) + c + Str(b) + "="
Text1.Text = ""
Else
Command1.Caption = "完成测试"
End If
End Sub
Private Sub Command2_Click() ‘判断按钮
If c = "+" Then
If a + b = Val(Text1.Text) Then s = s + 10
Else
If {#blank#}3{#/blank#}Then s = s + 10 '(3)
End If
Label3.Caption = "得分:" + Str(s)
End Sub