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

2024-11-15 03:33:00
推荐回答(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
是不是这效果