关于用vb做计算器的问题
展开全部
最简单的计算器就是仅仅计算加减乘除,既然是计算就是二个操作数之间的运算,首先在文本框中输入第一个操作数,在点击运算符时,将它保存在一个变量中,并且文本框清零,在输入第二个操作数,点击 “=”号时,将第二个操作数保存在另外的一个变量中,然后根据点击的运算符进行计算,计算结果显示在文本框中就可以了。
非常简单
Dim CZS1 As Single, CZS2 As Single, Strr As String
Private Sub Command1_Click(Index As Integer)
Dim InD As Integer
InD = Index
Text1.Text = Text1.Text & InD
End Sub
Private Sub Command2_Click(Index As Integer)
Dim XXA As Integer
XXA = Index
Strr = Command2(XXA).Caption
CZS1 = Val(Text1.Text)
Text1.Text = ""
End Sub
Private Sub Command3_Click()
CZS2 = Val(Text1.Text)
Text1.Text = ""
Select Case Strr
Case "+"
Text1.Text = CZS1 + CZS2
Case "-"
Text1.Text = CZS1 - CZS2
Case "*"
Text1.Text = CZS1 * CZS2
Case "/"
If CZS2 = 0 Then
MsgBox "除数不能为0,请重新输入除数!"
Text1.Text = ""
Else
Text1.Text = CZS1 / CZS2
End If
End Select
End Sub
Private Sub Command4_Click()
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command5_Click()
Text1.Text = ""
End Sub
Private Sub CommandXSD_Click()
Text1.Text = Text1.Text & "."
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询