这是一个四则运算器 可以显示表达式
但连续运算时出错 清空也有问题
我的程序问题出在哪?大家帮忙看看!!
大家可以现场改 也可以发到
通过qq告诉我56723225
Option Explicit
Dim st1 As String
Dim st2 As String
'Dim op As String
'Dim num As String
Dim Num1 As String
Dim Num2 As String
Dim Oper As String
Dim OperN As String
Dim Isnum As Boolean
Dim result As StringPrivate Sub op_Click(Index As Integer)
If Isnum And Oper = 1 Then
Isnum = False
Oper = 2
ElseIf Isnum Then
Call results_Click
Oper = 2
Isnum = False
End If
st2 = "" + op(Index).Caption
result = st1 + st2
Text1.Text = result
OperN = Index
Text1.Text = result
End SubPrivate Sub dot_Click()
If Isnum Then
If Oper = 1 Then
If Not InStr(st1, ".") > 0 Then
st1 = st1 + "."
result = Num1
Text1.Text = result
End If
ElseIf Oper = 2 Then
If Not InStr(st2, ".") > 0 Then
st2 = st2 + "."
result = st1 + st2
Text1.Text = result
End If
End If
End If
End SubPrivate Sub Form_Load()
Oper = 1
Isnum = True
st1 = ""
st2 = ""
Num1 = 0
Num2 = 0
result = ""
End SubPrivate Sub results_Click()
If Oper < 2 Then
Exit Sub
End If
Select Case OperN
Case 0
Num1 = Num1 / Num2
Case 1
Num1 = Num1 * Num2
Case 2
Num1 = Num1 - Num2
Case 3
Num1 = Num1 + Num2
End SelectOper = 0
Isnum = False
st1 = ""
st2 = Str(Num1)
result = Num1
Text1.Text = result
End SubPrivate Sub cmdclear_Click()
If Isnum Then
If Oper = 1 Then
st1 = "0"
Num1 = 0
result = st1
Text1.Text = result
ElseIf Oper = 2 Then
st2 = ""
Num2 = 0
result = st1 + st2
Text1.Text = result
End If
End If
End SubPrivate Sub num_Click(Index As Integer)
If Isnum Then
If Oper = 1 Then
st1 = st1 + Right(Str(Index), 1)
Num1 = Val(st1)
result = st1
Text1.Text = result
ElseIf Oper = 2 Then
st2 = st2 + Right(Str(Index), 1)
Num2 = Val(st2)
result = st1 + st2
Text1.Text = result
End If
ElseIf Not Isnum Then ' and oper<>0 then
Isnum = True
st1 = st1 + st2 + ""
Oper = 2
Num2 = Index
st2 = Right(Str(Num2), 1)
result = st1 + st2
Text1.Text = result
End If
End Sub
但连续运算时出错 清空也有问题
我的程序问题出在哪?大家帮忙看看!!
大家可以现场改 也可以发到
通过qq告诉我56723225
Option Explicit
Dim st1 As String
Dim st2 As String
'Dim op As String
'Dim num As String
Dim Num1 As String
Dim Num2 As String
Dim Oper As String
Dim OperN As String
Dim Isnum As Boolean
Dim result As StringPrivate Sub op_Click(Index As Integer)
If Isnum And Oper = 1 Then
Isnum = False
Oper = 2
ElseIf Isnum Then
Call results_Click
Oper = 2
Isnum = False
End If
st2 = "" + op(Index).Caption
result = st1 + st2
Text1.Text = result
OperN = Index
Text1.Text = result
End SubPrivate Sub dot_Click()
If Isnum Then
If Oper = 1 Then
If Not InStr(st1, ".") > 0 Then
st1 = st1 + "."
result = Num1
Text1.Text = result
End If
ElseIf Oper = 2 Then
If Not InStr(st2, ".") > 0 Then
st2 = st2 + "."
result = st1 + st2
Text1.Text = result
End If
End If
End If
End SubPrivate Sub Form_Load()
Oper = 1
Isnum = True
st1 = ""
st2 = ""
Num1 = 0
Num2 = 0
result = ""
End SubPrivate Sub results_Click()
If Oper < 2 Then
Exit Sub
End If
Select Case OperN
Case 0
Num1 = Num1 / Num2
Case 1
Num1 = Num1 * Num2
Case 2
Num1 = Num1 - Num2
Case 3
Num1 = Num1 + Num2
End SelectOper = 0
Isnum = False
st1 = ""
st2 = Str(Num1)
result = Num1
Text1.Text = result
End SubPrivate Sub cmdclear_Click()
If Isnum Then
If Oper = 1 Then
st1 = "0"
Num1 = 0
result = st1
Text1.Text = result
ElseIf Oper = 2 Then
st2 = ""
Num2 = 0
result = st1 + st2
Text1.Text = result
End If
End If
End SubPrivate Sub num_Click(Index As Integer)
If Isnum Then
If Oper = 1 Then
st1 = st1 + Right(Str(Index), 1)
Num1 = Val(st1)
result = st1
Text1.Text = result
ElseIf Oper = 2 Then
st2 = st2 + Right(Str(Index), 1)
Num2 = Val(st2)
result = st1 + st2
Text1.Text = result
End If
ElseIf Not Isnum Then ' and oper<>0 then
Isnum = True
st1 = st1 + st2 + ""
Oper = 2
Num2 = Index
st2 = Right(Str(Num2), 1)
result = st1 + st2
Text1.Text = result
End If
End Sub
我估计是这儿出问题了。
Num1 = val(Num1) + Num2
这样就可以了。
你为什么不把num1,num2定义成double型的?