我的计算器我想要实现连加功能,请问怎么修改啊,帮帮忙
Option Explicit
Dim startyunsuan As Boolean '是否开始运算
Dim yunsuan As Long '运算标志
Dim firstyunsuan As Double '先前的操作数
Private Sub cmd09_Click(Index As Integer)
If Val(txtDisp.Text) <= 0 Then '数字0-9
txtDisp.Text = Index
Else
txtDisp.Text = txtDisp.Text & Index
End If
End Sub
Private Sub cmdBackspace_Click()
On Error Resume Next
txtDisp = Left(txtDisp, Len(txtDisp) - 1) '退格键
End Sub
Private Sub cmdFuhao_Click(Index As Integer)
Select Case Index
Case 0
yunsuan = 1
Evaluate
Case 1
yunsuan = 2
Evaluate
Case 2
yunsuan = 3
Evaluate
Case 3
yunsuan = 4
Evaluate
Case 4
DisposeResult
End Select
End Sub
Private Sub Evaluate() '四则运算赋值
firstyunsuan = Val(txtDisp)
startyunsuan = True
txtDisp = ""
End Sub
Private Sub DisposeResult() '处理计算结果
On Error GoTo ToExit '打开错误陷阱
Select Case yunsuan '操作标志
Case 1
txtDisp = firstyunsuan + Val(txtDisp)
Case 2
txtDisp = firstyunsuan - Val(txtDisp)
Case 3
txtDisp = firstyunsuan * Val(txtDisp)
Case 4
txtDisp = firstyunsuan / Val(txtDisp)
End Select
yunsuan = 0 '操作标志清0
Exit Sub
ToExit:
MsgBox "除数不能为0!", vbOKOnly, "Error" '提示出错
On Error Resume Next '遇到错误不管,继续执行
End Sub
Private Sub cmdClearAll_Click() 'C按钮清除所有的运算结果
yunsuan = 0
txtDisp = "0"
End Sub
Private Sub cmdClearLastInput_Click() 'CE按钮清除最后一次输入的数字
txtDisp = "0"
End Sub
Private Sub txtDisp_KeyPress(KeyAscii As Integer)
If KeyAscii < 47 Or KeyAscii > 57 Then '文本框只允许输入数字0-9还有小数点
KeyAscii = 0
End If
End Sub