简易计算器代码1

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

'num1 = 1, num2 = 2/22/222

'按=

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.cwhello.com/36452.html

如有侵犯您的合法权益请发邮件951076433@qq.com联系删除

(0)
趣易编程趣易编程订阅用户
上一篇 2022年5月18日
下一篇 2022年5月19日

相关推荐

联系我们

QQ:951076433

在线咨询:点击这里给我发消息邮件:951076433@qq.com工作时间:周一至周五,9:30-18:30,节假日休息