VB做加减乘除的代码是什么啊? 或者是怎么做加减乘除 ?

Private Sub Command1_Click()
Text3 = Val(Text1) + Val(Text2)
End Sub
这个是做加法的 ,做减法只要变换其中的 + 改为 -- 就可以了 ,但是这样做要做2个程序 ,我只想做一个程序就可以实现 , 可以吗?

代码如下
'已增加操作数正确性验证及 除数不能为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
温馨提示:答案为网友推荐,仅供参考
相似回答