设计简单计算器,VB题,请高手帮忙啊!

来源:百度知道 编辑:UC知道 时间:2024/05/27 07:08:13
4.设计一个“简单计算器” 。

程序图示地址:

要求:
1)在窗体上从左到右依次引入Text1、Text2、Text3三个文本框。
2)在窗体上引入1个标签Label1。将Label1用于显示“=”号。
3)在窗体上从左到右依次引入Command1、 Command2、 Command3、 Command4。单击按钮,分别实现加、减、乘、除功能,结果显示在text3文本框中。
4)text3文本框 锁定,不允许输入或修改其中的值

求高手写下详细代码,太谢谢了!
效果示例地址:
http://zrmei.com/swf/sl2.jpg
http://zrmei.com/swf/sl3.jpg

Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub

Private Sub Command2_Click()
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End Sub

Private Sub Command3_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub

Private Sub Command4_Click()
If Val(Text2.Text) = 0 Then Text3.Text = "error": Exit Sub
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Sub

Private Sub Form_Load()
Text3.Locked = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Command1.Caption = "+"
Command2.Caption = "-"
Command3.Caption = "*"
Command4.Caption = "÷"
End Sub