关于计算器的有关问题
关于计算器的问题
[code=VB][/code]
Dim num1, t, d, cat, a
Private Sub Command1_Click(Index As Integer)
If Index <= 9 Then
If t > 9 And t <> 15 Then
Text1.Text = Index
Else
If Text1.Text = "0" Then
Text1.Text = Index
Else
Text1.Text = Text1.Text & Index
End If
End If
Else
Select Case Index
Case 10 '加法
If cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
End If
cat = 1
p = 0
Case 11 '减法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
End If
cat = 2
p = 0
Case 12 '乘法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
End If
cat = 3
p = 0
Case 13 '除法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
cat = 4
p = 0
Case 15 '小数点
If p = 0 Then
Text1.Text = Text1.Text + "."
p = 1
End If
Case 16 '等于
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
p = 0
End Select
End If
t = Index
End Sub
Private Sub Command2_Click()
a = Len(Text1.Text)
If a = 1 Then
Text1.Text = 0
Else
Text1.Text = Left(Text1.Text, a - 1)
[code=VB][/code]
Dim num1, t, d, cat, a
Private Sub Command1_Click(Index As Integer)
If Index <= 9 Then
If t > 9 And t <> 15 Then
Text1.Text = Index
Else
If Text1.Text = "0" Then
Text1.Text = Index
Else
Text1.Text = Text1.Text & Index
End If
End If
Else
Select Case Index
Case 10 '加法
If cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
End If
cat = 1
p = 0
Case 11 '减法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
End If
cat = 2
p = 0
Case 12 '乘法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
End If
cat = 3
p = 0
Case 13 '除法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
cat = 4
p = 0
Case 15 '小数点
If p = 0 Then
Text1.Text = Text1.Text + "."
p = 1
End If
Case 16 '等于
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
p = 0
End Select
End If
t = Index
End Sub
Private Sub Command2_Click()
a = Len(Text1.Text)
If a = 1 Then
Text1.Text = 0
Else
Text1.Text = Left(Text1.Text, a - 1)