图片中没显示结果显示在哪,我就将结果在text3中输出,具体代码如下,有疑问,可追问:
Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
End Sub
Private Sub Command1_Click()
If Combo1.Text = "+" Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
ElseIf Combo1.Text = "-" Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
ElseIf Combo1.Text = "*" Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
ElseIf Combo1.Text = "/" Then
If Text3.Text = "0" Then
MsgBox "除数不能为0!"
Else
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End If
End If
End Sub
假设按钮名称是command1,文本框名称分别是text1和text2,组合框名称是combo1,代码如下:
Private Sub Command1_Click()
If Combo1.Text = "+" Then MsgBox Val(Text1) + Val(Text2)
If Combo1.Text = "-" Then MsgBox Val(Text1) - Val(Text2)
If Combo1.Text = "*" Then MsgBox Val(Text1) * Val(Text2)
If Combo1.Text = "/" Then MsgBox Val(Text1) / Val(Text2)
End Sub