谁能帮我调试一下,看看哪块错了

Viking_ 2004-11-21 09:14:29
Dim op1, op2 As Object
Dim decimalflag As Short
Dim numops As Short
Dim lastinput As Object
Dim opflag As Object
Dim tempreadout As Object
Public Sub operatorcal(ByVal myoperator As Integer)
Dim index As Short = myoperator
tempreadout = Readout.Text
If lastinput = "NUMS" Then
numops = numops + 1
End If
Select Case numops
Case 0
If myoperator = 3 And lastinput <> "NEG" Then
Readout.Text = "-" & Readout.Text
lastinput = "NEG"
End If
Case 1
op1 = Readout.Text
If myoperator = 3 And lastinput <> "NUMS" And CDbl(opflag) <> 4 Then
Readout.Text = "-"
lastinput = "NEG"
End If
Case 2
op2 = tempreadout
Select Case opflag
Case 1
op1 = CDbl(op1) + CDbl(op2)
Case 3
op1 = CDbl(op1) - CDbl(op2)
Case 2
op1 = CDbl(op1) * CDbl(op2)
Case 0
If op2 = 0 Then
MsgBox("除数不能为零", 48, "计算器")
Else
op1 = CDbl(op1) / CDbl(op2)
End If
Case 4
op1 = CDbl(op2)
End Select
Readout.Text = op1
numops = 1
End Select
If lastinput <> "NEG" Then
lastinput = "OPS"
opflag = myoperator
End If
End Sub
Public Sub calculate(ByVal mynumber As Integer)
Dim index As Short = mynumber
If lastinput <> "NUMS" Then
Readout.Text = Format(0, ".")
decimalflag = False
End If
If decimalflag Then
Readout.Text = Readout.Text & mynumber
Else
If Readout.Text = "" Then
Readout.Text = mynumber & "."
Else
Readout.Text = Mid(Readout.Text, 1, Len(Readout.Text) - 1) & mynumber & "."
End If
End If
If lastinput = "NEG" Then
Readout.Text = "-" & Readout.Text
End If
End Sub

Private Sub DecimalDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DecimalDot.Click
If lastinput = "NEG" Then
Readout.Text = Format(0, "-0.")
ElseIf lastinput <> "NUMS" Then
Readout.Text = Format(0, "0.")
End If
decimalflag = True
lastinput = "NUMS"
End Sub

Private Sub Number1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number1.Click
calculate(1)
End Sub

Private Sub Number2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number2.Click
calculate(2)
End Sub

Private Sub Number3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number3.Click
calculate(3)
End Sub

Private Sub Number4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number4.Click
calculate(4)
End Sub

Private Sub Number5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number5.Click
calculate(5)
End Sub

Private Sub Number6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number6.Click
calculate(6)
End Sub

Private Sub Number7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number7.Click
calculate(7)
End Sub

Private Sub Number8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number8.Click
calculate(8)
End Sub

Private Sub Number9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number9.Click
calculate(9)
End Sub


Private Sub Operator0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Operator0.Click
operatorcal(0)
End Sub

Private Sub Operator1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Operator1.Click
operatorcal(1)
End Sub

Private Sub Operator2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Operator2.Click
operatorcal(2)
End Sub

Private Sub Operator3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Operator3.Click
operatorcal(3)
End Sub

Private Sub Operator4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Operator4.Click
operatorcal(4)
End Sub

Private Sub percent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles percent.Click
Readout.Text = CStr(CDbl(Readout.Text) / 100)
lastinput = "Ops"
opflag = "%"
numops = numops + 1
decimalflag = True
End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Readout.Text = Format(0, "0.")
op1 = 0
op2 = 0
Form1_Load(Me, New System.EventArgs)
End Sub

Private Sub CancelEntity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelEntity.Click
Readout.Text = Format(0, "0.")
decimalflag = False
lastinput = "CE"
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
decimalflag = False
numops = 0
lastinput = "NONE"
opflag = "5"
Readout.Text = Format(0, "0.")
End Sub
编译时代码没错,但出来后,乱七八糟的
...全文
64 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
水如烟 2004-11-21
  • 打赏
  • 举报
回复
你参考一下这个加法器:
\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VB Samples\WinForms-Calc\Calc

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧