VisualBasic简易计算器

大家好!这是我第一次发表文章,如有错误,请指导,我必会采纳!

首先,新建一个窗体,将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=计算

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值