数字计算完以后,在点1的按钮,就接着连着计算后的数!这怎么解决啊!?
以下是我部分代码
Dim a As Integer
Dim b As Integer
Dim c As String
Dim x As IntegerPrivate Sub a0_Click(Index As Integer)
If x = 1 Then
Text1.Text = "0"
If Text1.Text = "" Then
Text1.Text = Text1.Text & "0"
Exit Sub
End If
End If
Text1.Text = Text1.Text & "0"
End SubPrivate Sub a1_Click(Index As Integer)
If x = 1 Then
Text1.Text = ""
End If
If x = 1 And Text1.Text = "" Then
Text1.Text = Text1.Text & "1"
End If
Text1.Text = Text1.Text & "1"
End SubPrivate Sub a2_Click(Index As Integer)
If x = 1 Then
Text1.Text = "2"
End If
If Text1.Text <> "" Then
Text1.Text = " "
Text1.Text = Text1.Text & "2"
End IfText1.Text = Text1.Text & "2"
End SubPrivate Sub a3_Click(Index As Integer)
x = True
Text1.Text = Text1.Text & "3"
End SubPrivate Sub a4_Click(Index As Integer)
Text1.Text = Text1.Text & "4"
End SubPrivate Sub a5_Click(Index As Integer)Text1.Text = Text1.Text & "5"
End SubPrivate Sub a6_Click(Index As Integer)Text1.Text = Text1.Text & "6"
End SubPrivate Sub a7_Click(Index As Integer)Text1.Text = Text1.Text & "7"
End SubPrivate Sub a8_Click(Index As Integer)Text1.Text = Text1.Text & "8"
End SubPrivate Sub a9_Click(Index As Integer)Text1.Text = Text1.Text & "9"
End SubPrivate Sub b1_Click(Index As Integer)
a = Val(Text1.Text)
b = 1
Text1.Text = ""
End SubPrivate Sub b2_Click(Index As Integer)
a = Val(Text1.Text)
b = 2
Text1.Text = ""End SubPrivate Sub b3_Click(Index As Integer)
a = Val(Text1.Text)
b = 3
Text1.Text = ""
End SubPrivate Sub b4_Click(Index As Integer)
a = Val(Text1.Text)
b = 4
Text1.Text = ""
End SubPrivate Sub b5_Click()
Select Case b
Case 1
c = Str(a + Val(Text1.Text))
x = 1
Case 2
c = Str(a - Val(Text1.Text))
Case 3
c = Str(a * Val(Text1.Text))
Case 4
If Text1.Text = "0" Then
MsgBox "除数不能为零!"
Else
Text1.Text = Str(a / Val(Text1.Text))
End If
Case Else
Text1.Text = ""
End Select
Text1.Text = c
End SubPrivate Sub return_Click(Index As Integer)
Text1.Text = "0"
End SubPrivate Sub start_Click(Index As Integer)
End
End Sub
Private Sub Text1_Change()
Text1.Text = Val(Text1.Text)
End Sub
以下是我部分代码
Dim a As Integer
Dim b As Integer
Dim c As String
Dim x As IntegerPrivate Sub a0_Click(Index As Integer)
If x = 1 Then
Text1.Text = "0"
If Text1.Text = "" Then
Text1.Text = Text1.Text & "0"
Exit Sub
End If
End If
Text1.Text = Text1.Text & "0"
End SubPrivate Sub a1_Click(Index As Integer)
If x = 1 Then
Text1.Text = ""
End If
If x = 1 And Text1.Text = "" Then
Text1.Text = Text1.Text & "1"
End If
Text1.Text = Text1.Text & "1"
End SubPrivate Sub a2_Click(Index As Integer)
If x = 1 Then
Text1.Text = "2"
End If
If Text1.Text <> "" Then
Text1.Text = " "
Text1.Text = Text1.Text & "2"
End IfText1.Text = Text1.Text & "2"
End SubPrivate Sub a3_Click(Index As Integer)
x = True
Text1.Text = Text1.Text & "3"
End SubPrivate Sub a4_Click(Index As Integer)
Text1.Text = Text1.Text & "4"
End SubPrivate Sub a5_Click(Index As Integer)Text1.Text = Text1.Text & "5"
End SubPrivate Sub a6_Click(Index As Integer)Text1.Text = Text1.Text & "6"
End SubPrivate Sub a7_Click(Index As Integer)Text1.Text = Text1.Text & "7"
End SubPrivate Sub a8_Click(Index As Integer)Text1.Text = Text1.Text & "8"
End SubPrivate Sub a9_Click(Index As Integer)Text1.Text = Text1.Text & "9"
End SubPrivate Sub b1_Click(Index As Integer)
a = Val(Text1.Text)
b = 1
Text1.Text = ""
End SubPrivate Sub b2_Click(Index As Integer)
a = Val(Text1.Text)
b = 2
Text1.Text = ""End SubPrivate Sub b3_Click(Index As Integer)
a = Val(Text1.Text)
b = 3
Text1.Text = ""
End SubPrivate Sub b4_Click(Index As Integer)
a = Val(Text1.Text)
b = 4
Text1.Text = ""
End SubPrivate Sub b5_Click()
Select Case b
Case 1
c = Str(a + Val(Text1.Text))
x = 1
Case 2
c = Str(a - Val(Text1.Text))
Case 3
c = Str(a * Val(Text1.Text))
Case 4
If Text1.Text = "0" Then
MsgBox "除数不能为零!"
Else
Text1.Text = Str(a / Val(Text1.Text))
End If
Case Else
Text1.Text = ""
End Select
Text1.Text = c
End SubPrivate Sub return_Click(Index As Integer)
Text1.Text = "0"
End SubPrivate Sub start_Click(Index As Integer)
End
End Sub
Private Sub Text1_Change()
Text1.Text = Val(Text1.Text)
End Sub
name = 4句代码的计算器
form = 3个text 1个command 4个option
设置:
1\3个text的值清空
2\4个option的标题分别为"+-*/" [option1=+ option2=- ...4=/]
3\command的标题为"="
4\位置排序: text1 下面 有4个 option 再下面是text2 再下面是 command 最下面是text3
效果:运行后可以是个简单的计算器...
==================
代码:Private Sub Command1_Click()
If Option1 Then Text3 = Val(Text1) + Val(Text2)
If Option2 Then Text3 = Val(Text1) - Val(Text2)
If Option3 Then Text3 = Val(Text1) * Val(Text2)
If Option4 And Val(Text2) <> 0 Then Text3 = Val(Text1) / Val(Text2)
End Sub
不过好像button的名字都已经被改了'数字键
Private Sub btnNumber_Click(Index As Integer)Text1.Text = Text1.Text & Index
'抱歉,很久不用VB了,不知道这样写是不是可以End Sub'+ - * / 键
Private Sub btnOperate_Click(Index As Integer)
a = Val(Text1.Text)
b = Index
Text1.Text = ""
End Sub 还有小数点的输入,backspace和delete,最后是数字溢出的判断等等
其他的应该没什么了吧
Private Sub Command1_Click()
Shell "calc.exe"
End Sub
搞定,嘿嘿