1个回答
2014-03-12
展开全部
不明白你是否要做一个简易的计算器,如是,可以参考如下:其中command2,command3,command4,command5代表加减乘除按钮,Command1代表清除按钮,Command6代表计算按钮,两个label控件,一个是用来指定计算符的,由点击按钮实现,另一个是“=”,代码如下:Option ExplicitPrivate Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End SubPrivate Sub Command2_Click()
Label1.Caption = "+"
End SubPrivate Sub Command3_Click()
Label1.Caption = "-"
End SubPrivate Sub Command4_Click()
Label1.Caption = "*"
End SubPrivate Sub Command5_Click()
Label1.Caption = "÷"
End SubPrivate Sub Command6_Click()
Select Case Label1.Caption
Case "+": Text3.Text = Val(Text1.Text) + Val(Text2.Text)
Case "-": Text3.Text = Val(Text1.Text) - Val(Text2.Text)
Case "*": Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Case "÷": Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Select
End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End SubPrivate Sub Command2_Click()
Label1.Caption = "+"
End SubPrivate Sub Command3_Click()
Label1.Caption = "-"
End SubPrivate Sub Command4_Click()
Label1.Caption = "*"
End SubPrivate Sub Command5_Click()
Label1.Caption = "÷"
End SubPrivate Sub Command6_Click()
Select Case Label1.Caption
Case "+": Text3.Text = Val(Text1.Text) + Val(Text2.Text)
Case "-": Text3.Text = Val(Text1.Text) - Val(Text2.Text)
Case "*": Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Case "÷": Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询