VB简易计算器代码怎么写

按照我上面的结构来进行编写,要怎么实现功能呢?求大神

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
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-10-08

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

追问

frm文件怎么打开?

追答

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

追问

你这个有个缺陷,没输入数字时按删除就会出错,清除就不会

追答 '把这一句:
  If Index = 13  Then Text1 = Left(Text1, Len(Text1) - 1)
 '改成:
 If Index = 13 And Len(Text1) > 0 Then Text1 = Left(Text1, Len(Text1) - 1)
 '就可以了。

本回答被提问者采纳
相似回答