Option Explicit
Dim t As Integer
Dim ppp As Integer
Dim Num1 As Integer, Num2 As Integer '两个操作数
Dim SExp As String
Dim Result As Single '计算结果
Dim NOk As Integer, NError As Integer '统计计算正确与错误数
Private Sub Form_Load()
' 通过产生随机数生成表达式
Dim NOp As Integer, Op As String * 1 '操作符
Randomize '初始化随机数生成器
Num1 = Int(10 * Rnd + 1) '产生1-10之间的操作数
Num2 = Int(10 * Rnd + 1) '产生1-10之间的操作数
NOp = Int(4 * Rnd + 1) '产生1-4之间的操作代码
Select Case NOp
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
If Num1 < Num2 Then t = Num2: Num2 = Num1: Num1 = t
Result = Num1 - Num2
Case 3
Op = "×"
Result = Num1 * Num2
Case 4
Op = "÷"
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "="
Label1 = SExp
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1) = Result Then
Picture1.Print SExp; Text1; Tab(10); "√ " '计算正确
NOk = NOk + 1
Else
Picture1.Print SExp; Text1; Tab(10); "×" '计算错误
NError = NError + 1
End If
Text1 = "" '下一个表达式生成
Text1.SetFocus
Form_Load
End If
End Sub
Private Sub Command1_Click()
ppp = Int(NOk / (NOk + NError) * 100)
On Error Resume Next
Label1 = ""
Picture1.Print "----------------------------------"
Picture1.Print "一共计算 " & (NOk + NError) & " 道题";
Picture1.Print "得分 "; ppp
If ppp >= 90 Then
MsgBox "优 通过", , "提示"
ElseIf ppp >= 80 Then
MsgBox "良 通过", , "提示"
ElseIf ppp >= 70 Then
MsgBox "中 通过", , "提示"
ElseIf ppp >= 60 Then
MsgBox "及格 通过", , "提示"
Else
MsgBox "不及格 未通过", 5 + vbExclamation, "提示"
Text1 = "" '下一个表达式生成
Text1.SetFocus
Form_Load
End If
End Sub
Dim t As Integer
Dim ppp As Integer
Dim Num1 As Integer, Num2 As Integer '两个操作数
Dim SExp As String
Dim Result As Single '计算结果
Dim NOk As Integer, NError As Integer '统计计算正确与错误数
Private Sub Form_Load()
' 通过产生随机数生成表达式
Dim NOp As Integer, Op As String * 1 '操作符
Randomize '初始化随机数生成器
Num1 = Int(10 * Rnd + 1) '产生1-10之间的操作数
Num2 = Int(10 * Rnd + 1) '产生1-10之间的操作数
NOp = Int(4 * Rnd + 1) '产生1-4之间的操作代码
Select Case NOp
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
If Num1 < Num2 Then t = Num2: Num2 = Num1: Num1 = t
Result = Num1 - Num2
Case 3
Op = "×"
Result = Num1 * Num2
Case 4
Op = "÷"
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "="
Label1 = SExp
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1) = Result Then
Picture1.Print SExp; Text1; Tab(10); "√ " '计算正确
NOk = NOk + 1
Else
Picture1.Print SExp; Text1; Tab(10); "×" '计算错误
NError = NError + 1
End If
Text1 = "" '下一个表达式生成
Text1.SetFocus
Form_Load
End If
End Sub
Private Sub Command1_Click()
ppp = Int(NOk / (NOk + NError) * 100)
On Error Resume Next
Label1 = ""
Picture1.Print "----------------------------------"
Picture1.Print "一共计算 " & (NOk + NError) & " 道题";
Picture1.Print "得分 "; ppp
If ppp >= 90 Then
MsgBox "优 通过", , "提示"
ElseIf ppp >= 80 Then
MsgBox "良 通过", , "提示"
ElseIf ppp >= 70 Then
MsgBox "中 通过", , "提示"
ElseIf ppp >= 60 Then
MsgBox "及格 通过", , "提示"
Else
MsgBox "不及格 未通过", 5 + vbExclamation, "提示"
Text1 = "" '下一个表达式生成
Text1.SetFocus
Form_Load
End If
End Sub