我的 vb计算器 编码那里出错了?

来源:百度知道 编辑:UC知道 时间:2024/06/05 20:16:08
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
If Text1.Text = "0." Then
Text1.Text = "0."
Else
Text1.Text = Text1.Text + "0"
End If

Case 1
If Text1.Text = "0." Then
Text1.Text = "1"
Else
Text1.Text = Text1.Text + "1"
End If

Case 2
If Text1.Text = "0." Then
Text1.Text = "2"
Else
Text1.Text = Text1.Text + "2"
End If

Case 3
If Text1.Text = "0." Then
Text1.Text = "3"
Else
Text1.Text = Text1.Text + "3"
End If

Case 4
If Text1.Text = "0." Then
Text1.Text = "4"
Else
Text1.Text = Text1.Text + "4"
End If

Case 5
If Text1.Text = "0." Then
Text1.Text = "5"
Else
Text1.Text = Text1.Text + "5"<

你这个当然算不出来。你在加减乘除时就已经将“0.”赋给B变量了,那你在等于时的B变量始终都是“0.”那你算什么都算不出来。
看看我给你改的。

还有:你在做这个计算器时,除了在“加”运算时最好不要用到“+”运算符,要用“&”连接符最安全。

Private Sub Command2_Click(Index As Integer)

If Text1.Text = "0." Then
Text1.Text = "0."
Else
Select Case Index
Case 1
a = Text1.Text
X = 1
Text1.Text = "0."
Case 2
X = 2
a = Text1.Text
Text1.Text = "0."
Case 3
X = 3
a = Text1.Text
Text1.Text = "0."
Case 4
X = 4
a = Text1.Text
Text1.Text = "0."
Case 0
b = Text1.Text
If X = 1 Then
c = a + b
ElseIf X = 2 Then
c = a - b
ElseIf X = 3 Then
c = a * b
ElseIf X = 4 Then
c = a / b
End If
Text1.Text = c

——————————————————加减乘除运行不出来
Case 5
Text1.Text = "0."
End Select
End If
End Sub

If Text1.Text = "0." Then
Text