VB简易计算器代码怎么写

按照我上面的结构来进行编写,要怎么实现功能呢?求大神... 按照我上面的结构来进行编写,要怎么实现功能呢?求大神 展开
 我来答
爱WUDEZHANG
2013-10-08 · TA获得超过915个赞
知道小有建树答主
回答量:524
采纳率:100%
帮助的人:189万
展开全部
Dim a(100) As Double
Dim n&
Dim Plus As Boolean
Dim yunsuan(100) As Integer '------------这里增加
Dim a100 As Double
Private Sub cmd1_Click()
If Plus = True Then
Plus = False
Text1.Text = "1"
Else
Text1.Text = Text1.Text & "1"
End If
End Sub

Private Sub cmd2_Click()
If Plus = True Then
Plus = False
Text1.Text = "2"
Else
Text1.Text = Text1.Text & "2"
End If
End Sub

Private Sub cmd3_Click()
If Plus = True Then
Plus = False
Text1.Text = "3"
Else
Text1.Text = Text1.Text & "3"
End If
End Sub

Private Sub cmd4_Click()
If Plus = True Then
Plus = False
Text1.Text = "4"
Else
Text1.Text = Text1.Text & "4"
End If
End Sub
Private Sub cmd5_Click()
If Plus = True Then
Plus = False
Text1.Text = "5"
Else
Text1.Text = Text1.Text & "5"
End If
End Sub
Private Sub cmd6_Click()
If Plus = True Then
Plus = False
Text1.Text = "6"
Else
Text1.Text = Text1.Text & "6"
End If
End Sub
Private Sub cmd7_Click()
If Plus = True Then
Plus = False
Text1.Text = "7"
Else
Text1.Text = Text1.Text & "7"
End If
End Sub
Private Sub cmd8_Click()
If Plus = True Then
Plus = False
Text1.Text = "8"
Else
Text1.Text = Text1.Text & "8"
End If
End Sub
Private Sub cmd9_Click()
If Plus = True Then
Plus = False
Text1.Text = "9"
Else
Text1.Text = Text1.Text & "9"
End If
End Sub
Private Sub cmd0_Click()
If Plus = True Then
Plus = False
Text1.Text = "0"
Else
Text1.Text = Text1.Text & "0"
End If
End Sub

Private Sub cmdDian_Click()
If Plus = True Then
Plus = False
Text1.Text = "0."
Else
Text1.Text = Text1.Text & "."
End If
End Sub

Private Sub cmdjia_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 0 '------这是在加号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdjian_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 1 '------这是在减号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdcheng_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 2 '------这是在乘号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdchu_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 3 '------这是在除号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdDengyu_Click() '-------这是等于号
If Plus = False Then
a(n) = Val(Text1.Text)
End If
a(100) = a(0) '初始为a(0)
For i = 1 To 99
If yunsuan(i - 1) = 0 Then '------如果是加
a(100) = a(100) + a(i)
ElseIf yunsuan(i - 1) = 1 Then '----------如果是减
a(100) = a(100) - a(i)
ElseIf yunsuan(i - 1) = 2 Then '-----xxx
a(100) = a(100) * a(i)
ElseIf yunsuan(i - 1) = 3 Then '--------///
a(100) = a(100) / a(i)
End If
Next
Plus = False
Text1.Text = a(100)
n = 0
a100 = a(100)
Erase a
a(0) = a100
Erase yunsuan '--------清理
End Sub

Private Sub Command17_Click()

Text1.Text = ""
Erase a
Erase yunsuan
n = 0
End Sub

Private Sub Form_Load()
Text1.Locked = True
n = 0
Plus = False
End Sub
Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 97 Then cmd1_Click
If KeyCode = 98 Then cmd2_Click
If KeyCode = 99 Then cmd3_Click
If KeyCode = 100 Then cmd4_Click
If KeyCode = 101 Then cmd5_Click
If KeyCode = 102 Then cmd6_Click
If KeyCode = 103 Then cmd7_Click
If KeyCode = 104 Then cmd8_Click
If KeyCode = 105 Then cmd9_Click
If KeyCode = 96 Then cmd0_Click
If KeyCode = 110 Then cmdDian_Click
If KeyCode = 109 Then cmdjian_Click
If KeyCode = 13 Then cmdDengyu_Click
If KeyCode = 111 Then cmdchu_Click
If KeyCode = 107 Then cmdjia_Click
If KeyCode = 106 Then cmdcheng_Click
Debug.Print KeyCode, vbKey1
End Sub
忠成静0O
2013-10-08 · TA获得超过1049个赞
知道小有建树答主
回答量:1114
采纳率:100%
帮助的人:886万
展开全部

'帮你做了一个简单有效的给你参考,请采纳,谢谢!

更多追问追答
追问
frm文件怎么打开?
追答

vb6编程软件就可以直接打开了,这是一个窗口文件。

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式