用Excel VBA 做简单的计算器 求代码

2024年11月15日 03:33
有1个网友回答
网友(1):

Private Sub CommandButton1_Click()
Select Case ComboBox1.Text
Case "+"
CommandButton1.Caption = Val(TextBox1.Text) + Val(TextBox2.Text)
Case "-"
CommandButton1.Caption = Val(TextBox1.Text) - Val(TextBox2.Text)
Case "*"
CommandButton1.Caption = Val(TextBox1.Text) * Val(TextBox2.Text)
Case "/"
CommandButton1.Caption = Val(TextBox1.Text) / Val(TextBox2.Text)
End Select
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "+"
ComboBox1.AddItem "-"
ComboBox1.AddItem "*"
ComboBox1.AddItem "/"
End Sub
是不是这效果