以下是用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