怎么用VB做一个四则运算的程序
Dim m As Integer, n As Integer, Operator As String
Private Sub Command1_Click()
Static Counter As Integer, Right_num As Integer, Error_num As Integer
If Val(Text5.Text) = Operation(m, n) Then
Right_num = Right_num + 1
List1.AddItem m & Operator & n & "=" & Text5.Text & Space(2) & "√"
Else
Error_num = Error_num + 1
List1.AddItem m & Operator & n & "=" & Text5.Text & Space(2) & "×"
End If
Text1.Text = Right_num + Error_num
Text2.Text = Right_num
Text3.Text = Error_num
Text4.Text = Int(Right_num / (Right_num + Error_num) * 100 + 0.5)
Text5.Text = ""
Text5.SetFocus
GenerativeFormulas
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Activate()
Text5.Text = ""
Text5.SetFocus
GenerativeFormulas
End Sub
Private Function Operation(ByVal x As Integer, ByVal y As Integer) As Integer
Select Case Operator
Case "÷"
Operation = x / y
Case "﹣"
Operation = x - y
Case "+"
Operation = x + y
Case "×"
Operation = x * y
End Select
End Function
Private Sub GenerativeFormulas()
Randomize
m = Int(Rnd * 10 + 1)
n = Int(Rnd * 10 + 1)
If m Mod n = 0 Then
Operator = "÷"
ElseIf m >= n Then
Operator = "﹣"
ElseIf Rnd > 0.5 Then
Operator = "+"
Else
Operator = "×"
End If
Label5.Caption = m & Operator & n & "="
End Sub
界面设计:
运行效果: