03xc600
asked on
how to make a program more object oriented
i need to make this more object oriented the stuff that is double commented ( '' ) is stuff that i propose putting into the program. The stuff with a single comment (') is what i have to do to it. I am really not understanding this approach to make it more object oriented. I really do not know where to begin.........i am somewhat of a rookie. I know that the code looks long, but most of it is generated from the form. Any help would be greatly appreciated.
''Protected op1 As Long
''Protected op2 as long
''protected theresult as string
''public property operand1()as string
''get
''return op1
''end get
''set (byval value as string)
''if isnumeric(value) then
''op1 = long.parse(value)
''else
''end if
''end property
''public property result()as string
''get
''return result
''end get
''set (byval value as string)
''the result = value
''end set
''end property
''public mustoverride sub docalc()
''end class
''public class addcalculation
''inherits calculation
''public overrides sub docalc()
''dim x as long
''x = op1 + op2
''the result = x. to string
''end sub
Public Class calculatorForm
Inherits System.Windows.Forms.Form
'THESE VARIABLE DECLARATIONS NEED TO BE REPLACED------
'TO IMPLEMENT THE OBJECT-ORIENTED APPROACH
Dim firstOperand As Long
Dim secondOperand As Long
Dim op As String
'------------------------- ---------- ---------- --------
Dim calcStep As Integer = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents outputLabel As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Butto n
Friend WithEvents Button2 As System.Windows.Forms.Butto n
Friend WithEvents Button3 As System.Windows.Forms.Butto n
Friend WithEvents Button4 As System.Windows.Forms.Butto n
Friend WithEvents Button5 As System.Windows.Forms.Butto n
Friend WithEvents Button6 As System.Windows.Forms.Butto n
Friend WithEvents Button7 As System.Windows.Forms.Butto n
Friend WithEvents Button8 As System.Windows.Forms.Butto n
Friend WithEvents Button9 As System.Windows.Forms.Butto n
Friend WithEvents Button10 As System.Windows.Forms.Butto n
Friend WithEvents clButton As System.Windows.Forms.Butto n
Friend WithEvents equalButton As System.Windows.Forms.Butto n
Friend WithEvents intDivButton As System.Windows.Forms.Butto n
Friend WithEvents multButton As System.Windows.Forms.Butto n
Friend WithEvents subtractButton As System.Windows.Forms.Butto n
Friend WithEvents divButton As System.Windows.Forms.Butto n
Friend WithEvents addButton As System.Windows.Forms.Butto n
Friend WithEvents expButton As System.Windows.Forms.Butto n
Friend WithEvents ceButton As System.Windows.Forms.Butto n
Friend WithEvents negNumButton As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.outputLabel = New System.Windows.Forms.Label
Me.clButton = New System.Windows.Forms.Butto n
Me.Button1 = New System.Windows.Forms.Butto n
Me.Button2 = New System.Windows.Forms.Butto n
Me.Button3 = New System.Windows.Forms.Butto n
Me.Button4 = New System.Windows.Forms.Butto n
Me.Button5 = New System.Windows.Forms.Butto n
Me.Button6 = New System.Windows.Forms.Butto n
Me.Button7 = New System.Windows.Forms.Butto n
Me.Button8 = New System.Windows.Forms.Butto n
Me.Button9 = New System.Windows.Forms.Butto n
Me.Button10 = New System.Windows.Forms.Butto n
Me.equalButton = New System.Windows.Forms.Butto n
Me.intDivButton = New System.Windows.Forms.Butto n
Me.multButton = New System.Windows.Forms.Butto n
Me.subtractButton = New System.Windows.Forms.Butto n
Me.divButton = New System.Windows.Forms.Butto n
Me.addButton = New System.Windows.Forms.Butto n
Me.expButton = New System.Windows.Forms.Butto n
Me.ceButton = New System.Windows.Forms.Butto n
Me.negNumButton = New System.Windows.Forms.Butto n
Me.SuspendLayout()
'
'outputLabel
'
Me.outputLabel.Font = New System.Drawing.Font("Micro soft Sans Serif", 12.0!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.outputLabel.Location = New System.Drawing.Point(16, 8)
Me.outputLabel.Name = "outputLabel"
Me.outputLabel.Size = New System.Drawing.Size(256, 24)
Me.outputLabel.TabIndex = 0
'
'clButton
'
Me.clButton.Enabled = False
Me.clButton.Location = New System.Drawing.Point(16, 200)
Me.clButton.Name = "clButton"
Me.clButton.Size = New System.Drawing.Size(64, 40)
Me.clButton.TabIndex = 1
Me.clButton.Text = "CL"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 40)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 40)
Me.Button1.TabIndex = 3
Me.Button1.Text = "1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(80, 40)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 40)
Me.Button2.TabIndex = 4
Me.Button2.Text = "2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(144, 40)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 40)
Me.Button3.TabIndex = 5
Me.Button3.Text = "3"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(16, 80)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 40)
Me.Button4.TabIndex = 6
Me.Button4.Text = "4"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(80, 80)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(64, 40)
Me.Button5.TabIndex = 7
Me.Button5.Text = "5"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(144, 80)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(64, 40)
Me.Button6.TabIndex = 13
Me.Button6.Text = "6"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(16, 120)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(64, 40)
Me.Button7.TabIndex = 12
Me.Button7.Text = "7"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(80, 120)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(64, 40)
Me.Button8.TabIndex = 11
Me.Button8.Text = "8"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(144, 120)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(64, 40)
Me.Button9.TabIndex = 10
Me.Button9.Text = "9"
'
'Button10
'
Me.Button10.Location = New System.Drawing.Point(80, 160)
Me.Button10.Name = "Button10"
Me.Button10.Size = New System.Drawing.Size(64, 40)
Me.Button10.TabIndex = 9
Me.Button10.Text = "0"
'
'equalButton
'
Me.equalButton.Enabled = False
Me.equalButton.Location = New System.Drawing.Point(16, 160)
Me.equalButton.Name = "equalButton"
Me.equalButton.Size = New System.Drawing.Size(64, 40)
Me.equalButton.TabIndex = 8
Me.equalButton.Text = "="
'
'intDivButton
'
Me.intDivButton.Enabled = False
Me.intDivButton.Location = New System.Drawing.Point(144, 160)
Me.intDivButton.Name = "intDivButton"
Me.intDivButton.Size = New System.Drawing.Size(64, 40)
Me.intDivButton.TabIndex = 19
Me.intDivButton.Text = "\"
'
'multButton
'
Me.multButton.Enabled = False
Me.multButton.Location = New System.Drawing.Point(208, 120)
Me.multButton.Name = "multButton"
Me.multButton.Size = New System.Drawing.Size(64, 40)
Me.multButton.TabIndex = 18
Me.multButton.Text = "*"
'
'subtractButton
'
Me.subtractButton.Enabled = False
Me.subtractButton.Location = New System.Drawing.Point(208, 80)
Me.subtractButton.Name = "subtractButton"
Me.subtractButton.Size = New System.Drawing.Size(64, 40)
Me.subtractButton.TabIndex = 17
Me.subtractButton.Text = "-"
'
'divButton
'
Me.divButton.Enabled = False
Me.divButton.Location = New System.Drawing.Point(208, 160)
Me.divButton.Name = "divButton"
Me.divButton.Size = New System.Drawing.Size(64, 40)
Me.divButton.TabIndex = 16
Me.divButton.Text = "/"
'
'addButton
'
Me.addButton.Enabled = False
Me.addButton.Location = New System.Drawing.Point(208, 40)
Me.addButton.Name = "addButton"
Me.addButton.Size = New System.Drawing.Size(64, 40)
Me.addButton.TabIndex = 15
Me.addButton.Text = "+"
'
'expButton
'
Me.expButton.Enabled = False
Me.expButton.Location = New System.Drawing.Point(208, 200)
Me.expButton.Name = "expButton"
Me.expButton.Size = New System.Drawing.Size(64, 40)
Me.expButton.TabIndex = 14
Me.expButton.Text = "^"
'
'ceButton
'
Me.ceButton.Enabled = False
Me.ceButton.Location = New System.Drawing.Point(80, 200)
Me.ceButton.Name = "ceButton"
Me.ceButton.Size = New System.Drawing.Size(64, 40)
Me.ceButton.TabIndex = 20
Me.ceButton.Text = "CE"
'
'negNumButton
'
Me.negNumButton.Location = New System.Drawing.Point(144, 200)
Me.negNumButton.Name = "negNumButton"
Me.negNumButton.Size = New System.Drawing.Size(64, 40)
Me.negNumButton.TabIndex = 21
Me.negNumButton.Text = "+/-"
'
'calculatorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(280, 246)
Me.Controls.Add(Me.negNumB utton)
Me.Controls.Add(Me.ceButto n)
Me.Controls.Add(Me.intDivB utton)
Me.Controls.Add(Me.multBut ton)
Me.Controls.Add(Me.subtrac tButton)
Me.Controls.Add(Me.divButt on)
Me.Controls.Add(Me.addButt on)
Me.Controls.Add(Me.expButt on)
Me.Controls.Add(Me.Button6 )
Me.Controls.Add(Me.Button7 )
Me.Controls.Add(Me.Button8 )
Me.Controls.Add(Me.Button9 )
Me.Controls.Add(Me.Button1 0)
Me.Controls.Add(Me.equalBu tton)
Me.Controls.Add(Me.Button5 )
Me.Controls.Add(Me.Button4 )
Me.Controls.Add(Me.Button3 )
Me.Controls.Add(Me.Button2 )
Me.Controls.Add(Me.Button1 )
Me.Controls.Add(Me.clButto n)
Me.Controls.Add(Me.outputL abel)
Me.MaximizeBox = False
Me.Name = "calculatorForm"
Me.StartPosition = System.Windows.Forms.FormS tartPositi on.CenterS creen
Me.Text = "Calculator"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub DigitButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
'This is a common event handler for all ten of the digit (0-9) buttons
'The "sender", i.e., the button that triggered the event, is converted to a
'Button type object and assigned to "pushButton"
Dim pushedButton As Button
pushedButton = CType(sender, Button)
'The text of the sender (0-9) is passed as an argument
toggleOperatorsOn(pushedBu tton.Text)
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
op = addButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub subtractButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subtractButton.Click
op = subtractButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub multButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multButton.Click
op = multButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub divButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divButton.Click
op = divButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub intDivButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles intDivButton.Click
''calcobj = new divcalculation
''calcobj.operand1 = outputlabel.text
op = intDivButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub expButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expButton.Click
op = expButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub equalButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equalButton.Click
'THIS PROCEDURE NEEDS TO BE REWORKED TO DO THE CALCULATION USING OBJECT-
'ORIENTED PROGRAMMING
Dim result As Long
secondOperand = Long.Parse(outputLabel.Tex t)
''calcobj.operand = outputlabel.text
''calcobj.docalc
''outputlabel.text = calcobj.result
Select Case op
Case addButton.Text
result = firstOperand + secondOperand
outputLabel.Text = result.ToString()
Case subtractButton.Text()
result = firstOperand - secondOperand
outputLabel.Text = result.ToString()
Case multButton.Text()
result = firstOperand * secondOperand
outputLabel.Text = result.ToString()
Case divButton.Text()
If secondOperand <> 0 Then
result = firstOperand / secondOperand
outputLabel.Text = result.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case intDivButton.Text()
If secondOperand <> 0 Then
result = firstOperand \ secondOperand
Dim result2 As Long
result2 = firstOperand Mod secondOperand
outputLabel.Text = result.ToString() & " r " & result2.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case expButton.Text()
result = firstOperand ^ secondOperand
outputLabel.Text = result.ToString()
End Select
clButton.Enabled = False
End Sub
Private Sub negNumButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles negNumButton.Click
Dim currentNumber As String
currentNumber = outputLabel.Text
If InStr(currentNumber, "-") Then
outputLabel.Text = Replace(currentNumber, "-", "")
Else
outputLabel.Text = "-" & currentNumber
End If
End Sub
Private Sub ceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ceButton.Click
toggleOperatorsOff(0)
End Sub
Private Sub clButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clButton.Click
Select Case calcStep
Case 0, 1
toggleOperatorsOff(0)
Case 2
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Button10.Enabled = False
negNumButton.Enabled = False
calcStep = 1
toggleOperatorsOn("")
Case 3
outputLabel.Text = ""
equalButton.Enabled = False
End Select
End Sub
Private Sub toggleOperatorsOn(ByVal theDigit As String)
'concatenates the digit of the button that was pushed to the number
'displayed in the label
outputLabel.Text &= theDigit
clButton.Enabled = True
ceButton.Enabled = True
If calcStep >= 2 Then 'only enables the equal button if an operator has already been chosen
calcStep = 3
equalButton.Enabled = True
Else
calcStep = 1
addButton.Enabled = True
subtractButton.Enabled = True
multButton.Enabled = True
divButton.Enabled = True
intDivButton.Enabled = True
expButton.Enabled = True
equalButton.Enabled = False
End If
End Sub
Private Sub toggleOperatorsOff(ByVal changeToStep As Integer)
'this procedure disables all of the operator buttons
calcStep = changeToStep
If calcStep = 2 Then
'records the first operand (since "calcStep = 2" indicates that
'the operator has been selected and now it is time to enter the
'second operand
If outputLabel.Text <> "" Then
firstOperand = Long.Parse(outputLabel.Tex t)
End If
Else
equalButton.Enabled = False
ceButton.Enabled = False
clButton.Enabled = False
End If
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Button10.Enabled = True
negNumButton.Enabled = True
addButton.Enabled = False
subtractButton.Enabled = False
multButton.Enabled = False
divButton.Enabled = False
intDivButton.Enabled = False
expButton.Enabled = False
outputLabel.Text = ""
End Sub
End Class
''Protected op1 As Long
''Protected op2 as long
''protected theresult as string
''public property operand1()as string
''get
''return op1
''end get
''set (byval value as string)
''if isnumeric(value) then
''op1 = long.parse(value)
''else
''end if
''end property
''public property result()as string
''get
''return result
''end get
''set (byval value as string)
''the result = value
''end set
''end property
''public mustoverride sub docalc()
''end class
''public class addcalculation
''inherits calculation
''public overrides sub docalc()
''dim x as long
''x = op1 + op2
''the result = x. to string
''end sub
Public Class calculatorForm
Inherits System.Windows.Forms.Form
'THESE VARIABLE DECLARATIONS NEED TO BE REPLACED------
'TO IMPLEMENT THE OBJECT-ORIENTED APPROACH
Dim firstOperand As Long
Dim secondOperand As Long
Dim op As String
'-------------------------
Dim calcStep As Integer = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents outputLabel As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Butto
Friend WithEvents Button2 As System.Windows.Forms.Butto
Friend WithEvents Button3 As System.Windows.Forms.Butto
Friend WithEvents Button4 As System.Windows.Forms.Butto
Friend WithEvents Button5 As System.Windows.Forms.Butto
Friend WithEvents Button6 As System.Windows.Forms.Butto
Friend WithEvents Button7 As System.Windows.Forms.Butto
Friend WithEvents Button8 As System.Windows.Forms.Butto
Friend WithEvents Button9 As System.Windows.Forms.Butto
Friend WithEvents Button10 As System.Windows.Forms.Butto
Friend WithEvents clButton As System.Windows.Forms.Butto
Friend WithEvents equalButton As System.Windows.Forms.Butto
Friend WithEvents intDivButton As System.Windows.Forms.Butto
Friend WithEvents multButton As System.Windows.Forms.Butto
Friend WithEvents subtractButton As System.Windows.Forms.Butto
Friend WithEvents divButton As System.Windows.Forms.Butto
Friend WithEvents addButton As System.Windows.Forms.Butto
Friend WithEvents expButton As System.Windows.Forms.Butto
Friend WithEvents ceButton As System.Windows.Forms.Butto
Friend WithEvents negNumButton As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.outputLabel = New System.Windows.Forms.Label
Me.clButton = New System.Windows.Forms.Butto
Me.Button1 = New System.Windows.Forms.Butto
Me.Button2 = New System.Windows.Forms.Butto
Me.Button3 = New System.Windows.Forms.Butto
Me.Button4 = New System.Windows.Forms.Butto
Me.Button5 = New System.Windows.Forms.Butto
Me.Button6 = New System.Windows.Forms.Butto
Me.Button7 = New System.Windows.Forms.Butto
Me.Button8 = New System.Windows.Forms.Butto
Me.Button9 = New System.Windows.Forms.Butto
Me.Button10 = New System.Windows.Forms.Butto
Me.equalButton = New System.Windows.Forms.Butto
Me.intDivButton = New System.Windows.Forms.Butto
Me.multButton = New System.Windows.Forms.Butto
Me.subtractButton = New System.Windows.Forms.Butto
Me.divButton = New System.Windows.Forms.Butto
Me.addButton = New System.Windows.Forms.Butto
Me.expButton = New System.Windows.Forms.Butto
Me.ceButton = New System.Windows.Forms.Butto
Me.negNumButton = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'outputLabel
'
Me.outputLabel.Font = New System.Drawing.Font("Micro
Me.outputLabel.Location = New System.Drawing.Point(16, 8)
Me.outputLabel.Name = "outputLabel"
Me.outputLabel.Size = New System.Drawing.Size(256, 24)
Me.outputLabel.TabIndex = 0
'
'clButton
'
Me.clButton.Enabled = False
Me.clButton.Location = New System.Drawing.Point(16, 200)
Me.clButton.Name = "clButton"
Me.clButton.Size = New System.Drawing.Size(64, 40)
Me.clButton.TabIndex = 1
Me.clButton.Text = "CL"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 40)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 40)
Me.Button1.TabIndex = 3
Me.Button1.Text = "1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(80, 40)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 40)
Me.Button2.TabIndex = 4
Me.Button2.Text = "2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(144, 40)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 40)
Me.Button3.TabIndex = 5
Me.Button3.Text = "3"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(16, 80)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 40)
Me.Button4.TabIndex = 6
Me.Button4.Text = "4"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(80, 80)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(64, 40)
Me.Button5.TabIndex = 7
Me.Button5.Text = "5"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(144, 80)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(64, 40)
Me.Button6.TabIndex = 13
Me.Button6.Text = "6"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(16, 120)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(64, 40)
Me.Button7.TabIndex = 12
Me.Button7.Text = "7"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(80, 120)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(64, 40)
Me.Button8.TabIndex = 11
Me.Button8.Text = "8"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(144, 120)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(64, 40)
Me.Button9.TabIndex = 10
Me.Button9.Text = "9"
'
'Button10
'
Me.Button10.Location = New System.Drawing.Point(80, 160)
Me.Button10.Name = "Button10"
Me.Button10.Size = New System.Drawing.Size(64, 40)
Me.Button10.TabIndex = 9
Me.Button10.Text = "0"
'
'equalButton
'
Me.equalButton.Enabled = False
Me.equalButton.Location = New System.Drawing.Point(16, 160)
Me.equalButton.Name = "equalButton"
Me.equalButton.Size = New System.Drawing.Size(64, 40)
Me.equalButton.TabIndex = 8
Me.equalButton.Text = "="
'
'intDivButton
'
Me.intDivButton.Enabled = False
Me.intDivButton.Location = New System.Drawing.Point(144, 160)
Me.intDivButton.Name = "intDivButton"
Me.intDivButton.Size = New System.Drawing.Size(64, 40)
Me.intDivButton.TabIndex = 19
Me.intDivButton.Text = "\"
'
'multButton
'
Me.multButton.Enabled = False
Me.multButton.Location = New System.Drawing.Point(208, 120)
Me.multButton.Name = "multButton"
Me.multButton.Size = New System.Drawing.Size(64, 40)
Me.multButton.TabIndex = 18
Me.multButton.Text = "*"
'
'subtractButton
'
Me.subtractButton.Enabled = False
Me.subtractButton.Location
Me.subtractButton.Name = "subtractButton"
Me.subtractButton.Size = New System.Drawing.Size(64, 40)
Me.subtractButton.TabIndex
Me.subtractButton.Text = "-"
'
'divButton
'
Me.divButton.Enabled = False
Me.divButton.Location = New System.Drawing.Point(208, 160)
Me.divButton.Name = "divButton"
Me.divButton.Size = New System.Drawing.Size(64, 40)
Me.divButton.TabIndex = 16
Me.divButton.Text = "/"
'
'addButton
'
Me.addButton.Enabled = False
Me.addButton.Location = New System.Drawing.Point(208, 40)
Me.addButton.Name = "addButton"
Me.addButton.Size = New System.Drawing.Size(64, 40)
Me.addButton.TabIndex = 15
Me.addButton.Text = "+"
'
'expButton
'
Me.expButton.Enabled = False
Me.expButton.Location = New System.Drawing.Point(208, 200)
Me.expButton.Name = "expButton"
Me.expButton.Size = New System.Drawing.Size(64, 40)
Me.expButton.TabIndex = 14
Me.expButton.Text = "^"
'
'ceButton
'
Me.ceButton.Enabled = False
Me.ceButton.Location = New System.Drawing.Point(80, 200)
Me.ceButton.Name = "ceButton"
Me.ceButton.Size = New System.Drawing.Size(64, 40)
Me.ceButton.TabIndex = 20
Me.ceButton.Text = "CE"
'
'negNumButton
'
Me.negNumButton.Location = New System.Drawing.Point(144, 200)
Me.negNumButton.Name = "negNumButton"
Me.negNumButton.Size = New System.Drawing.Size(64, 40)
Me.negNumButton.TabIndex = 21
Me.negNumButton.Text = "+/-"
'
'calculatorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(280, 246)
Me.Controls.Add(Me.negNumB
Me.Controls.Add(Me.ceButto
Me.Controls.Add(Me.intDivB
Me.Controls.Add(Me.multBut
Me.Controls.Add(Me.subtrac
Me.Controls.Add(Me.divButt
Me.Controls.Add(Me.addButt
Me.Controls.Add(Me.expButt
Me.Controls.Add(Me.Button6
Me.Controls.Add(Me.Button7
Me.Controls.Add(Me.Button8
Me.Controls.Add(Me.Button9
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.equalBu
Me.Controls.Add(Me.Button5
Me.Controls.Add(Me.Button4
Me.Controls.Add(Me.Button3
Me.Controls.Add(Me.Button2
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.clButto
Me.Controls.Add(Me.outputL
Me.MaximizeBox = False
Me.Name = "calculatorForm"
Me.StartPosition = System.Windows.Forms.FormS
Me.Text = "Calculator"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub DigitButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
'This is a common event handler for all ten of the digit (0-9) buttons
'The "sender", i.e., the button that triggered the event, is converted to a
'Button type object and assigned to "pushButton"
Dim pushedButton As Button
pushedButton = CType(sender, Button)
'The text of the sender (0-9) is passed as an argument
toggleOperatorsOn(pushedBu
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
op = addButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub subtractButton_Click(ByVal
op = subtractButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub multButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multButton.Click
op = multButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub divButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divButton.Click
op = divButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub intDivButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles intDivButton.Click
''calcobj = new divcalculation
''calcobj.operand1 = outputlabel.text
op = intDivButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub expButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expButton.Click
op = expButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub equalButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equalButton.Click
'THIS PROCEDURE NEEDS TO BE REWORKED TO DO THE CALCULATION USING OBJECT-
'ORIENTED PROGRAMMING
Dim result As Long
secondOperand = Long.Parse(outputLabel.Tex
''calcobj.operand = outputlabel.text
''calcobj.docalc
''outputlabel.text = calcobj.result
Select Case op
Case addButton.Text
result = firstOperand + secondOperand
outputLabel.Text = result.ToString()
Case subtractButton.Text()
result = firstOperand - secondOperand
outputLabel.Text = result.ToString()
Case multButton.Text()
result = firstOperand * secondOperand
outputLabel.Text = result.ToString()
Case divButton.Text()
If secondOperand <> 0 Then
result = firstOperand / secondOperand
outputLabel.Text = result.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case intDivButton.Text()
If secondOperand <> 0 Then
result = firstOperand \ secondOperand
Dim result2 As Long
result2 = firstOperand Mod secondOperand
outputLabel.Text = result.ToString() & " r " & result2.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case expButton.Text()
result = firstOperand ^ secondOperand
outputLabel.Text = result.ToString()
End Select
clButton.Enabled = False
End Sub
Private Sub negNumButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles negNumButton.Click
Dim currentNumber As String
currentNumber = outputLabel.Text
If InStr(currentNumber, "-") Then
outputLabel.Text = Replace(currentNumber, "-", "")
Else
outputLabel.Text = "-" & currentNumber
End If
End Sub
Private Sub ceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ceButton.Click
toggleOperatorsOff(0)
End Sub
Private Sub clButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clButton.Click
Select Case calcStep
Case 0, 1
toggleOperatorsOff(0)
Case 2
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Button10.Enabled = False
negNumButton.Enabled = False
calcStep = 1
toggleOperatorsOn("")
Case 3
outputLabel.Text = ""
equalButton.Enabled = False
End Select
End Sub
Private Sub toggleOperatorsOn(ByVal theDigit As String)
'concatenates the digit of the button that was pushed to the number
'displayed in the label
outputLabel.Text &= theDigit
clButton.Enabled = True
ceButton.Enabled = True
If calcStep >= 2 Then 'only enables the equal button if an operator has already been chosen
calcStep = 3
equalButton.Enabled = True
Else
calcStep = 1
addButton.Enabled = True
subtractButton.Enabled = True
multButton.Enabled = True
divButton.Enabled = True
intDivButton.Enabled = True
expButton.Enabled = True
equalButton.Enabled = False
End If
End Sub
Private Sub toggleOperatorsOff(ByVal changeToStep As Integer)
'this procedure disables all of the operator buttons
calcStep = changeToStep
If calcStep = 2 Then
'records the first operand (since "calcStep = 2" indicates that
'the operator has been selected and now it is time to enter the
'second operand
If outputLabel.Text <> "" Then
firstOperand = Long.Parse(outputLabel.Tex
End If
Else
equalButton.Enabled = False
ceButton.Enabled = False
clButton.Enabled = False
End If
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Button10.Enabled = True
negNumButton.Enabled = True
addButton.Enabled = False
subtractButton.Enabled = False
multButton.Enabled = False
divButton.Enabled = False
intDivButton.Enabled = False
expButton.Enabled = False
outputLabel.Text = ""
End Sub
End Class
I think you would to program a object oriented calculator.
There you must extract all math function into one seperate class. After that you instantiate the class as a global object in your form
and call the functions from the class within your button code and set the form properties of your labels and buttons.
You must first think what only is the math code and what is your form code to extract the mathcode from your form.
There you must extract all math function into one seperate class. After that you instantiate the class as a global object in your form
and call the functions from the class within your button code and set the form properties of your labels and buttons.
You must first think what only is the math code and what is your form code to extract the mathcode from your form.
ASKER
True, it does meake it look very confusing. I will post it again and the comments in capitals are what i need to do. My goal is to make this more object oriented. This is probably just as long and cumbersome as it was before. The reason i put it up there like that was because it was easy to copy and paste into VB.net, if somebody wanted to se how the prog worked. Let me know if this is any more help
Thanks
Public Class calculatorForm
Inherits System.Windows.Forms.Form
'THESE VARIABLE DECLARATIONS NEED TO BE REPLACED------
'TO IMPLEMENT THE OBJECT-ORIENTED APPROACH
Dim firstOperand As Long
Dim secondOperand As Long
Dim op As String
'------------------------- ---------- ---------- --------
Dim calcStep As Integer = 0
Private Sub DigitButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
Dim pushedButton As Button
pushedButton = CType(sender, Button)
toggleOperatorsOn(pushedBu tton.Text)
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
op = addButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub subtractButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subtractButton.Click
op = subtractButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub multButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multButton.Click
op = multButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub divButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divButton.Click
op = divButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub intDivButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles intDivButton.Click
op = intDivButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub expButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expButton.Click
op = expButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub equalButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equalButton.Click
'THIS PROCEDURE NEEDS TO BE REWORKED TO DO THE CALCULATION USING OBJECT-
'ORIENTED PROGRAMMING
Dim result As Long
secondOperand = Long.Parse(outputLabel.Tex t)
Select Case op
Case addButton.Text
result = firstOperand + secondOperand
outputLabel.Text = result.ToString()
Case subtractButton.Text()
result = firstOperand - secondOperand
outputLabel.Text = result.ToString()
Case multButton.Text()
result = firstOperand * secondOperand
outputLabel.Text = result.ToString()
Case divButton.Text()
If secondOperand <> 0 Then
result = firstOperand / secondOperand
outputLabel.Text = result.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case intDivButton.Text()
If secondOperand <> 0 Then
result = firstOperand \ secondOperand
Dim result2 As Long
result2 = firstOperand Mod secondOperand
outputLabel.Text = result.ToString() & " r " & result2.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case expButton.Text()
result = firstOperand ^ secondOperand
outputLabel.Text = result.ToString()
End Select
clButton.Enabled = False
End Sub
Private Sub negNumButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles negNumButton.Click
Dim currentNumber As String
currentNumber = outputLabel.Text
If InStr(currentNumber, "-") Then
outputLabel.Text = Replace(currentNumber, "-", "")
Else
outputLabel.Text = "-" & currentNumber
End If
End Sub
Private Sub ceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ceButton.Click
toggleOperatorsOff(0)
End Sub
Private Sub clButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clButton.Click
Select Case calcStep
Case 0, 1
toggleOperatorsOff(0)
Case 2
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Button10.Enabled = False
negNumButton.Enabled = False
calcStep = 1
toggleOperatorsOn("")
Case 3
outputLabel.Text = ""
equalButton.Enabled = False
End Select
End Sub
Private Sub toggleOperatorsOn(ByVal theDigit As String)
'concatenates the digit of the button that was pushed to the number
'displayed in the label
outputLabel.Text &= theDigit
clButton.Enabled = True
ceButton.Enabled = True
If calcStep >= 2 Then 'only enables the equal button if an operator has already been chosen
calcStep = 3
equalButton.Enabled = True
Else
calcStep = 1
addButton.Enabled = True
subtractButton.Enabled = True
multButton.Enabled = True
divButton.Enabled = True
intDivButton.Enabled = True
expButton.Enabled = True
equalButton.Enabled = False
End If
End Sub
Private Sub toggleOperatorsOff(ByVal changeToStep As Integer)
'this procedure disables all of the operator buttons
calcStep = changeToStep
If calcStep = 2 Then
'records the first operand (since "calcStep = 2" indicates that
'the operator has been selected and now it is time to enter the
'second operand
If outputLabel.Text <> "" Then
firstOperand = Long.Parse(outputLabel.Tex t)
End If
Else
equalButton.Enabled = False
ceButton.Enabled = False
clButton.Enabled = False
End If
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Button10.Enabled = True
negNumButton.Enabled = True
addButton.Enabled = False
subtractButton.Enabled = False
multButton.Enabled = False
divButton.Enabled = False
intDivButton.Enabled = False
expButton.Enabled = False
outputLabel.Text = ""
End Sub
End Class
Thanks
Public Class calculatorForm
Inherits System.Windows.Forms.Form
'THESE VARIABLE DECLARATIONS NEED TO BE REPLACED------
'TO IMPLEMENT THE OBJECT-ORIENTED APPROACH
Dim firstOperand As Long
Dim secondOperand As Long
Dim op As String
'-------------------------
Dim calcStep As Integer = 0
Private Sub DigitButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
Dim pushedButton As Button
pushedButton = CType(sender, Button)
toggleOperatorsOn(pushedBu
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
op = addButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub subtractButton_Click(ByVal
op = subtractButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub multButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multButton.Click
op = multButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub divButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divButton.Click
op = divButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub intDivButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles intDivButton.Click
op = intDivButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub expButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles expButton.Click
op = expButton.Text '<--THIS LINE NEEDS TO BE REWORKED TO USE OBJECT-ORIENTED PROGRAMMING
toggleOperatorsOff(2)
End Sub
Private Sub equalButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles equalButton.Click
'THIS PROCEDURE NEEDS TO BE REWORKED TO DO THE CALCULATION USING OBJECT-
'ORIENTED PROGRAMMING
Dim result As Long
secondOperand = Long.Parse(outputLabel.Tex
Select Case op
Case addButton.Text
result = firstOperand + secondOperand
outputLabel.Text = result.ToString()
Case subtractButton.Text()
result = firstOperand - secondOperand
outputLabel.Text = result.ToString()
Case multButton.Text()
result = firstOperand * secondOperand
outputLabel.Text = result.ToString()
Case divButton.Text()
If secondOperand <> 0 Then
result = firstOperand / secondOperand
outputLabel.Text = result.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case intDivButton.Text()
If secondOperand <> 0 Then
result = firstOperand \ secondOperand
Dim result2 As Long
result2 = firstOperand Mod secondOperand
outputLabel.Text = result.ToString() & " r " & result2.ToString()
Else
outputLabel.Text = "DIVIDE BY 0 ERROR!"
End If
Case expButton.Text()
result = firstOperand ^ secondOperand
outputLabel.Text = result.ToString()
End Select
clButton.Enabled = False
End Sub
Private Sub negNumButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles negNumButton.Click
Dim currentNumber As String
currentNumber = outputLabel.Text
If InStr(currentNumber, "-") Then
outputLabel.Text = Replace(currentNumber, "-", "")
Else
outputLabel.Text = "-" & currentNumber
End If
End Sub
Private Sub ceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ceButton.Click
toggleOperatorsOff(0)
End Sub
Private Sub clButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clButton.Click
Select Case calcStep
Case 0, 1
toggleOperatorsOff(0)
Case 2
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
Button10.Enabled = False
negNumButton.Enabled = False
calcStep = 1
toggleOperatorsOn("")
Case 3
outputLabel.Text = ""
equalButton.Enabled = False
End Select
End Sub
Private Sub toggleOperatorsOn(ByVal theDigit As String)
'concatenates the digit of the button that was pushed to the number
'displayed in the label
outputLabel.Text &= theDigit
clButton.Enabled = True
ceButton.Enabled = True
If calcStep >= 2 Then 'only enables the equal button if an operator has already been chosen
calcStep = 3
equalButton.Enabled = True
Else
calcStep = 1
addButton.Enabled = True
subtractButton.Enabled = True
multButton.Enabled = True
divButton.Enabled = True
intDivButton.Enabled = True
expButton.Enabled = True
equalButton.Enabled = False
End If
End Sub
Private Sub toggleOperatorsOff(ByVal changeToStep As Integer)
'this procedure disables all of the operator buttons
calcStep = changeToStep
If calcStep = 2 Then
'records the first operand (since "calcStep = 2" indicates that
'the operator has been selected and now it is time to enter the
'second operand
If outputLabel.Text <> "" Then
firstOperand = Long.Parse(outputLabel.Tex
End If
Else
equalButton.Enabled = False
ceButton.Enabled = False
clButton.Enabled = False
End If
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Button10.Enabled = True
negNumButton.Enabled = True
addButton.Enabled = False
subtractButton.Enabled = False
multButton.Enabled = False
divButton.Enabled = False
intDivButton.Enabled = False
expButton.Enabled = False
outputLabel.Text = ""
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've created the 2nd class with an object to perform the calculations (and then additional inherited classes edepending on the type of calculation i want to do). In the original non-OO class, there is a 'case' statement that is used to determine which calculation to perform. However, I'm not sure of the syntax in VB to invoke this new class? (and take it away from the case statment) I take it the event method in the form object is what should invoke the Calculation object i created as a 2nd class....
thanks for the help!
thanks for the help!
Incidentally the code generated by the form really isn't that helpful here; just dumping out the entire source code makes it harder to read.