30分求VB加法计算器的详细做法

来源:百度知道 编辑:UC知道 时间:2024/06/09 18:26:55
VB6.0的,不是Flash的那种

Dim a As Double
Dim b As String
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub

Private Sub Command2_Click()
If InStr(Text1.Text, ".") = 0 Then
Text1.Text = Text1.Text & Command2.Caption
End If
If Left(Text1.Text, 1) = "." Then
Text1.Text = "0" & Text1.Text
End If
End Sub
Private Sub Command3_Click()
If Text1.Text = "" Then
Text1.Text = a
Exit Sub
End If

Select Case b
Case "+"
a = a + Val(Text1.Text)
Case "-"
a = a - Val(Text1.Text)
Case "X"
a = a * Val(Text1.Text)
Case "÷"
If Text1.Text = "0" Then
Text1.Text = "0"
Else
a = a / Val(Text1.Text)
End If
End Select
Text1.Text = a
End