Dim flag As Boolean
Dim addFlag As Boolean
Private Sub Command1_Click()
'加法
Static a As Long, b As Long
If Text1 = "" Then
MsgBox "error"
Exit Sub
End If
If addFlag Then
b = Val(Text1)
Text1 = a + b
a = Val(Text1)
Else
addFlag = True
a = Val(Text1)
End If
Text1.SetFocus
flag = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
‘过滤非数字字符
If KeyAscii < 49 Or KeyAscii > 57 Then
KeyAscii = 0
End If
If Not flag Then
flag = True
Text1 = ""
End If
End Sub
等于的按钮过程和加法相似,自己多琢磨下就出来了