代码如下
'已增加操作数正确性验证及 除数不能为0验证
Private Sub Command1_Click()
If IsNumeric(Text1.Text) And Text1.Text <> "" And IsNumeric(Text2.Text) And Text2.Text <> "" Then
Select Case Combo1.ListIndex
Case 0
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
Case 1
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
Case 2
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Case 3
If Val(Text1.Text) <> 0 Then
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
Else
MsgBox "除数不能为0", , "错误"
End If
End Select
Else
MsgBox "请输入操作数", , "错误"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
Combo1.ListIndex = 0
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Command1.Caption = "计算"
End Sub
温馨提示:答案为网友推荐,仅供参考