top of page

The Code

 

 

 

 Public Class MyClassHypotenuse


    '## Object-Orientated Programming ---------------------##

    '## Encapsulation - Create Self Contained Modules --------##

    '## Bind Processing Functions to Data --------------------##
    Public Function Hypotenuse(ByVal Side1 As Integer, ByVal Side2 As Integer)
        Hypotenuse = Format((
Side1 ^ 2) + (Side2 ^ 2))
    End Function
End Class

Public Class Form99

    Private Sub HypotenuseBtn_Click(sender As Object, e As EventArgs) Handles HypotenuseBtn.Click

        '## Dimension MyHypotenuse as Object of MyClassHypotenuse.vb ##
        Dim MyHypotenuse As Object


        '## Dimension Side Variables as Numeric Integer---------------- ##
        Dim Side1, Side2 As Integer

        '## Declare Lbl_ErrMsg as Invisible ----------------------------##
        LblErrorMessage.Visible = False
       
'## Reset Lbl_Answer.Text Forecolor to Blue --------------------##
        LblHypotenus.ForeColor = Color.Blue

        '## Try... Catch... End Try... Stucture -----------------------------##

        '## Error Handling Routine ------------------------------------##
        Try

            '## MyHypotenuse Inheritance of MyClassHypotenuse --------##
            '## Calculate Hypotenuse -----------------------------------##

            MyHypotenuse = New MyClassHypotenuse()
           
Side1 = TxtSide1.Text
            Side2 = TxtSide2.Text
            LblHypotenus.Text = (Math.Sqrt(MyHypotenuse.Hypotenuse(Side1, Side2)))

        Catch Non_Numeric As Exception
           
'## Subroutine[1] NonNumeric() ------------------------##

            '## Catch Non Numeric Input as Error -------------------##
            NonNumeric()


        End Try

    End Sub

    '## Sub[1] ---------------------------------------------------##
    '## Error Handling Message Routine ---------------------------##

    Sub NonNumeric()
       
LblHypotenus.ForeColor = Color.Red
       
LblHypotenus.Text = "Error"
       
'## Declare Lbl_ErrMsg as Visible ----------------------------##
       
LblErrorMessage.Visible = True
       
LblErrorMessage.ForeColor = Color.Red
       
LblErrorMessage.Text = " One of the entries is not a number! Try again!"
    End Sub

    Private Sub ClearBtn_Click(sender As Object, e As EventArgs) Handles ClearBtn.Click

        TxtSide1.Text = ""
       
TxtSide2.Text = ""
       
LblHypotenus.Text = ""
       
LblErrorMessage.Text = ""

    End Sub

    Private Sub IndexBtn_Click(sender As Object, e As EventArgs) Handles IndexBtn.Click
        Form97.Show()
        Me.Hide()
    End Sub

    Private Sub Form99_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       
LblHypotenus.Text = ""
       
LblErrorMessage.Text = ""
    End Sub


End Class

Website Links-173.jpg
bottom of page