用vb编写一个简单的计算器,有0-9数字,加减乘除,等于15个按钮,只有一个文本框,要求先输入一个数字,

2024-12-12 07:45:15
推荐回答(1个)
回答1:

下面是我练手时编的计算器的等号按钮事件,看能不能看清楚。
Private Sub Command14_Click()
d = ""
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Exit Sub
'c = Text1.Text
If b = "" Then Exit Sub
If e = "+" Then
d = f + b
Else
If e = "-" Then
d = f - b
Else
If e = "*" Then
d = f * b
Else
If e = "/" Then
If b = 0 Then
MsgBox "被除数不能为零!"
Exit Sub
End If
d = f / b
Else
MsgBox "错误操作!"
End If
End If
End If
End If
Text1.Text = d
b = ""
c = ""
e = ""
End Sub