Dim num1$, num2$, mark$, flag!
'按1
Private Sub Command1_Click()
isNumber 0
End Sub
Private Sub Command2_Click()
isNumber 1
End Sub
Private Sub Command3_Click()
isNumber 2
End Sub
Private Sub Command4_Click()
isNumber 3
End Sub
Private Sub Command5_Click()
isNumber 4
End Sub
Private Sub Command6_Click()
isNumber 5
End Sub
Private Sub Command7_Click()
isNumber 6
End Sub
Private Sub Command8_Click()
isNumber 7
End Sub
Private Sub Command9_Click()
isNumber 8
End Sub
Private Sub Command10_Click()
isNumber 9
End Sub
'按+
Private Sub Command11_Click()
isMark "+"
End Sub
Private Sub Command12_Click()
isMark "-"
End Sub
Private Sub Command13_Click()
isMark "×"
End Sub
Private Sub Command14_Click()
isMark "÷"
End Sub
'按=
Private Sub Command15_Click()
Dim res$
If mark = "+" Then
res = Val(num1) + Val(num2)
ElseIf mark = "-" Then
res = num2 – num1
ElseIf mark = "×" Then
res = num1 * num2
Else
If num2 <> 0 Then
res = num2 / num1
Else
MsgBox "除数不能为0"
Exit Sub
End If
End If
Text1.Text = res
Call Init
num1 = res
End Sub
Private Sub command16_click()
Call Init
Text1.Text = ""
End Sub
Private Function isNumber(n!)
If flag = 0 Then: num1 = ""
num1 = num1 & n
If flag = 0 Then: Text1.Text = ""
Text1.Text = Text1.Text & n
flag = 1
End Function
Private Function isMark(m$)
flag = 1
mark = m
Text1.Text = Text1.Text & m
num2 = num1
num1 = ""
End Function
Private Function Init()
flag = 0
num1 = ""
num2 = ""
mark = ""
End Function
如若转载,请注明出处:https://www.daxuejiayuan.com/11339.html