VB编写的简易计算器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
这是一个简易计算器的VB代码,下面是这个计算器的界面,有一个文本输入框和16个按钮
Dim OperatorState As Integer
Dim data1 As Integer
Dim result As Integer
Dim data2 As Integer
’下面是0~9十个按钮的点击事件
Private Sub Command9_Click()
Text1.Text = Text1.Text + "1"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text + "2"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text + "3"
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text + "4"
End Sub
Private Sub Command6_Click()
Text1.Text = Text1.Text + "5"
End Sub
Private Sub Command7_Click() Text1.Text = Text1.Text + "6" End Sub
Private Sub Command1_Click() Text1.Text = Text1.Text + "7" End Sub
Private Sub Command2_Click() Text1.Text = Text1.Text + "8" End Sub
Private Sub Command3_Click() Text1.Text = Text1.Text + "9" End Sub
Private Sub Command13_Click() Text1.Text = Text1.Text + "0" End Sub
’下面是清除键的代码
Private Sub Command15_Click() Text1.Text = ""
End Sub
’下面是加减乘除四个按钮的代码
Private Sub Command4_Click() data1 = Val(Text1.Text) OperatorState = 1
Text1.Text = ""
End Sub
Private Sub Command8_Click() data1 = Val(Text1.Text) OperatorState = 2
Text1.Text = ""
End Sub
Private Sub Command12_Click() data1 = Val(Text1.Text) OperatorState = 3
Text1.Text = ""
End Sub
Private Sub Command16_Click() data1 = Val(Text1.Text) OperatorState = 4
Text1.Text = ""
End Sub
’下面是等于号的的代码
Private Sub Command14_Click() data2 = Val(Text1.Text) Select Case OperatorState Case 1
result = data1 + data2
Case 2
result = data1 - data2
Case 3
result = data1 * data2
Case 4
result = data1 / data2
End Select
Text1.Text = Str$(result) End Sub