Solved

how to make a program more object oriented

Posted on 2006-11-06
5
152 Views
Last Modified: 2010-08-05
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.IContainer

    '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.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents Button8 As System.Windows.Forms.Button
    Friend WithEvents Button9 As System.Windows.Forms.Button
    Friend WithEvents Button10 As System.Windows.Forms.Button
    Friend WithEvents clButton As System.Windows.Forms.Button
    Friend WithEvents equalButton As System.Windows.Forms.Button
    Friend WithEvents intDivButton As System.Windows.Forms.Button
    Friend WithEvents multButton As System.Windows.Forms.Button
    Friend WithEvents subtractButton As System.Windows.Forms.Button
    Friend WithEvents divButton As System.Windows.Forms.Button
    Friend WithEvents addButton As System.Windows.Forms.Button
    Friend WithEvents expButton As System.Windows.Forms.Button
    Friend WithEvents ceButton As System.Windows.Forms.Button
    Friend WithEvents negNumButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.outputLabel = New System.Windows.Forms.Label
        Me.clButton = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Button5 = New System.Windows.Forms.Button
        Me.Button6 = New System.Windows.Forms.Button
        Me.Button7 = New System.Windows.Forms.Button
        Me.Button8 = New System.Windows.Forms.Button
        Me.Button9 = New System.Windows.Forms.Button
        Me.Button10 = New System.Windows.Forms.Button
        Me.equalButton = New System.Windows.Forms.Button
        Me.intDivButton = New System.Windows.Forms.Button
        Me.multButton = New System.Windows.Forms.Button
        Me.subtractButton = New System.Windows.Forms.Button
        Me.divButton = New System.Windows.Forms.Button
        Me.addButton = New System.Windows.Forms.Button
        Me.expButton = New System.Windows.Forms.Button
        Me.ceButton = New System.Windows.Forms.Button
        Me.negNumButton = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'outputLabel
        '
        Me.outputLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.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.negNumButton)
        Me.Controls.Add(Me.ceButton)
        Me.Controls.Add(Me.intDivButton)
        Me.Controls.Add(Me.multButton)
        Me.Controls.Add(Me.subtractButton)
        Me.Controls.Add(Me.divButton)
        Me.Controls.Add(Me.addButton)
        Me.Controls.Add(Me.expButton)
        Me.Controls.Add(Me.Button6)
        Me.Controls.Add(Me.Button7)
        Me.Controls.Add(Me.Button8)
        Me.Controls.Add(Me.Button9)
        Me.Controls.Add(Me.Button10)
        Me.Controls.Add(Me.equalButton)
        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.clButton)
        Me.Controls.Add(Me.outputLabel)
        Me.MaximizeBox = False
        Me.Name = "calculatorForm"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        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(pushedButton.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.Text)
        ''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.Text)
            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
0
Comment
Question by:03xc600
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17885331
How 'bout a little context?  What are you actually trying to do?

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.
0
 
LVL 11

Expert Comment

by:melmers
ID: 17887202
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.

0
 

Author Comment

by:03xc600
ID: 17893048
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(pushedButton.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.Text)

        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.Text)
            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



   

0
 
LVL 11

Accepted Solution

by:
melmers earned 500 total points
ID: 17895874
Create a second class with public properties for your First & Second Operand and the calculation function you would do with the 2 Operands.
The create a public function who gives you the result of your math function.
0
 

Author Comment

by:03xc600
ID: 17923176
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!

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now