码迷,mamicode.com
首页 > 其他好文 > 详细

用vb简单来做计算器

时间:2015-09-30 14:30:26      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

Dim a As Double, b As Double

Dim c As String

 

Private Sub Command10_Click()

Text2.Text = Text2.Text & "2"

End Sub

 

Private Sub Command11_Click()

Text2.Text = Text2.Text & "3"

End Sub

 

Private Sub Command12_Click()

a = Text2.Text

Text2.Text = ""

c = "+"

End Sub

 

Private Sub Command13_Click()

Text2.Text = Text2.Text & "."

End Sub

 

Private Sub Command14_Click()

a = Text2.Text

Text2.Text = ""

c = "/"

End Sub

 

Private Sub Command15_Click()

a = Text2.Text

Text2.Text = ""

c = "*"

End Sub

 

Private Sub Command16_Click()

a = Text2.Text

Text2.Text = ""

c = "-"

End Sub

 

Private Sub Command18_Click()

Text2.Text = ""

End Sub

 

Private Sub Command19_Click()

b = Text2.Text

If a = "0" Or b = "0 " Then MsgBox "除数为可以为0", vbExclamation, "tips": Exit Sub

Select Case c

Case "+"

Text2.Text = Val(a) + Val(b)

Case "-"

Text2.Text = Val(a) - Val(b)

Case "*"

Text2.Text = Val(a) * Val(b)

Case "/"

Text2.Text = Val(a) / Val(b)

If Val(a) = 0 Then

MsgBox "除数不可以为:“0”"

Text2.Text = ""

End If

If Val(b) = 0 Then

MsgBox "除数不可以为:“0”"

Text2.Text = ""

End If

End Select

 

End Sub

 

Private Sub Command2_Click()

Text2.Text = Text2.Tex t & "6"

End Sub

 

Private Sub Command3_Click()

Text2.Text = Text2.Text & "5"

End Sub

 

Private Sub Command4_Click()

Text2.Text = Text2.Text & "4"

End Sub

 

Private Sub Command5_Click()

Text2.Text = Text2.Text & "9"

End Sub

 

Private Sub Command6_Click()

Text2.Text = Text2.Text & "8"

End Sub

 

Private Sub Command7_Click()

Text2.Text = Text2.Text & "7"

End Sub

 

Private Sub Command8_Click()

Text2.Text = Text2.Text & "0"

End Sub

 

Private Sub Command9_Click()

Text2.Text = Text2.Text & "1"

End Sub

用vb简单来做计算器

标签:

原文地址:http://www.cnblogs.com/a369258147/p/4848916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!