Private Sub txtinput_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '按下回车开始判断
If Val(txtInput) = Result Then '输入的结果正确
Text1 = Text1 & SExp & txtInput & " √" & vbCrLf ' 计算正确
NOk = NOk + 1
Txtright.Text = " " & NOk
Else '输入的结果不正确
Text1 = Text1 & SExp & txtInput & " ×" & vbCrLf ' 计算错误
NError = NError + 1
txterr.Text = " " & NError
End If
GetData ' 再次调用GetData过程做下一题
End If
End Sub
Public Sub GetData()
Dim t%
Dim NOp As Integer, Op As String * 1 ' 操作符
Num1 = Int(90 * Rnd + 10) ' 产生1~10之间的操作数
Num2 = Int(90 * Rnd + 10) ' 产生1~10之间的操作数
NOp = Int(4 * Rnd + 1) ' 产生1~4之间的操作代码
Select Case NOp '将1~4转换成相应的操作符号
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
If Num1 < Num2 Then t = Num1: Num1 = Num2: Num2 = t
Result = Num1 - Num2
Case 3
Op = "×"
If Num1 > 10 And Num2 > 10 Then Num2 = Num2 \ 10
Result = Num1 * Num2
Case 4
Op = "÷"
If Num1 < Num2 Then t = Num1: Num1 = Num2: Num2 = t
If Num2 > 10 Then Num2 = Num2 \ 10
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "=" '将产生的操作数和操作符号组成当前题目
Form1.lblExp = SExp
End Sub
If KeyAscii = 13 Then '按下回车开始判断
If Val(txtInput) = Result Then '输入的结果正确
Text1 = Text1 & SExp & txtInput & " √" & vbCrLf ' 计算正确
NOk = NOk + 1
Txtright.Text = " " & NOk
Else '输入的结果不正确
Text1 = Text1 & SExp & txtInput & " ×" & vbCrLf ' 计算错误
NError = NError + 1
txterr.Text = " " & NError
End If
GetData ' 再次调用GetData过程做下一题
End If
End Sub
Public Sub GetData()
Dim t%
Dim NOp As Integer, Op As String * 1 ' 操作符
Num1 = Int(90 * Rnd + 10) ' 产生1~10之间的操作数
Num2 = Int(90 * Rnd + 10) ' 产生1~10之间的操作数
NOp = Int(4 * Rnd + 1) ' 产生1~4之间的操作代码
Select Case NOp '将1~4转换成相应的操作符号
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
If Num1 < Num2 Then t = Num1: Num1 = Num2: Num2 = t
Result = Num1 - Num2
Case 3
Op = "×"
If Num1 > 10 And Num2 > 10 Then Num2 = Num2 \ 10
Result = Num1 * Num2
Case 4
Op = "÷"
If Num1 < Num2 Then t = Num1: Num1 = Num2: Num2 = t
If Num2 > 10 Then Num2 = Num2 \ 10
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "=" '将产生的操作数和操作符号组成当前题目
Form1.lblExp = SExp
End Sub