代码编程(代码怎么编写)

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

    
本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 cloud@ksuyun.com 举报,一经查实,本站将立刻删除。
如若转载,请注明出处:https://www.daxuejiayuan.com/11339.html