| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 726 人关注过本帖
标题:关于vb.net计算器debug问题
只看楼主 加入收藏
pinkpig
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-10-5
收藏
 问题点数:0 回复次数:1 
关于vb.net计算器debug问题

以下是用vb.net编写的计算器,哪位高手能帮助debug一下.并且在需要debug的地方告诉我解释呢?急需!!
Public Class Form1

' fTerm1 is used to store the value of the first term
' nOperation is used to identify the operation performed, the value are:
' 1: addition, 2: subtraction, 3: multiplication, 4: division, 0:null
Public nOperation As Integer
Public fTerm1 As Long

' bEnter is used to identify whether the user has just started to enter a value or not
' bTerm1 is used to identify whether the user enter the term1 (= true) or term2 (= false)
Public bEnter, bTerm1 As Boolean

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
nOperation = 1
TextBox.Text = "0"
fTerm1 = 0
bEnter = True
bTerm1 = False
End Sub

Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click
nOperation = 1
TextBox.Text = "0"
fTerm1 = 0
bEnter = True
bTerm1 = False
End Sub

Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "0"
bEnter = False
Else
TextBox.Text += "0"
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "1"
bEnter = False
Else
TextBox.Text += "1"
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "2"
bEnter = False
Else
TextBox.Text += "2"
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "3"
bEnter = False
Else
TextBox.Text += "3"
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "4"
bEnter = False
Else
TextBox.Text += "4"
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "5"
bEnter = False
Else
TextBox.Text += "5"
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "7"
bEnter = False
Else
TextBox.Text += "7"
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "7"
bEnter = False
Else
TextBox.Text += "7"
End If
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "8"
bEnter = False
Else
TextBox.Text += "8"
End If
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If TextBox.Text = "0" And bEnter Then
TextBox.Text = "9"
bEnter = False
Else
TextBox.Text += "9"
End If
End Sub

Private Sub ButtonCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalculate.Click
Select Case nOperation
Case 1 'addition
fTerm1 += CDbl(TextBox.Text)
TextBox.Text = fTerm1
Case 2 'subtraction
fTerm1 -= CDbl(TextBox.Text)
TextBox.Text = fTerm1
Case 3 'multiplication
fTerm1 *= CDbl(TextBox.Text)
TextBox.Text = fTerm1
Case 4 'division
fTerm1 /= CDbl(TextBox.Text)
TextBox.Text = fTerm1
Case Else
End Select
nOperation = 1
bEnter = True
bTerm1 = True
End Sub

Private Sub ButtonAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAddition.Click
If bTerm1 Then
fTerm1 = CLng(TextBox.Text)
bTerm1 = False
Else
ButtonCalculate.PerformClick()
End If
bEnter = True
nOperation = 1 'addition
End Sub

Private Sub ButtonSubtraction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubtraction.Click
If bTerm1 Then
fTerm1 = CLng(TextBox.Text)
bTerm1 = False
Else
ButtonCalculate.PerformClick()
End If
bEnter = True
nOperation = 2 'subtraction
End Sub

Private Sub ButtonMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMultiplication.Click
If bTerm1 Then
fTerm1 = CLng(TextBox.Text)
bTerm1 = False
Else
ButtonCalculate.PerformClick()
End If
bEnter = True
nOperation = 3 'multiplication
End Sub

Private Sub ButtonDivision_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDivision.Click
If bTerm1 Then
fTerm1 = CLng(TextBox.Text)
bTerm1 = False
Else
ButtonCalculate.PerformClick()
End If
bEnter = True
nOperation = 4 'division
End Sub


End Class

搜索更多相关主题的帖子: 计算器 debug used Public value 
2006-10-05 17:47
蓝の魂
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-9-22
收藏
得分:0 

这样做代码很杂!
试试这样做
Public Sub AddEvent()
For Each i As Control In Me.Controls
If TypeOf i Is Button Then
AddHandler i.Click, AddressOf Button_Click
End If
Next
End Sub
Public Sub RemoveEvent()
For Each i As Control In Me.Controls
If TypeOf i Is Button Then
RemoveHandler i.Click, AddressOf Button_Click
End If
Next
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'全部按钮事件都在这
Dim bn As Button = CType(sender, Button)
Dim c As String = bn.Text
Select Case c
Case "1/x"
Case "0" To "9"
Case "+"
Case "-"
Case "*"
Case "/"
Case Else
End Select
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddEvent()
End Sub

Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
RemoveEvent()
End Sub
对VB.net感兴趣的请加入15636854讨论群
我Q是:406485989

2006-10-10 20:48
快速回复:关于vb.net计算器debug问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017439 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved