大家好!这是我第一次发表文章,如有错误,请指导,我必会采纳!
首先,新建一个窗体,将Form1的Caption属性改为简易计算器
然后,依次添加以下控件:Text*2,Label*1,Command*5,属性分别改为(Text*2,Label*1)font=小二
(Text*2)Caption="",(Command*5)Caption="+","-","*","/"
接下来是代码:
Command1
Private Sub Command1_Click()
Label1.Caption = "+"
End Sub
Command2
Private Sub Command2_Click()
Label1.Caption = "-"
End Sub
Command3
Private Sub Command3_Click()
Label1.Caption = "*"
End Sub
Command4
Private Sub Command4_Click()
Label1.Caption = "/"
End Sub
Command5
Private Sub Command5_Click()
a = Label1.Caption
b = Text1.Text
c = Text2.Text
b = Val(b)
c = Val(c)
If a = "+" Then
d = (b + c)
MsgBox ("答案是" & d)
ElseIf a = "-" Then
d = (b - c)
MsgBox ("答案是" & d)
ElseIf a = "*" Then
d = (b * c)
MsgBox ("答案是" & d)
ElseIf a = "/" Then
MsgBox ("答案是" & d)
End If
End Sub
Command1=加
Command2=减
Command3=乘
Command4=除
Command5=计算