Shane Partridge
Visual Basic 2013
The Code
Public Class MyClassPounds_KilogramsConversion
'## ============ Object-Orientated Programming ==================##
'## [1]Encapsulation - Self Contained Modules -----------------------------------##
'## [2]Inheritance - Structured Class to be passed by Hierarchy Inheritance --------##
'## [3]Polymorphism - Modules represent Real World Objects known as Classes ----##
'## Dimension DecimalPlace as String = "n2" Number Decimal Place = 2 ------------##
Dim DecimalPlace As String = "n2"
Public Function Pound_KilogramConversion(ByVal ConvertPound_Kilogram As Integer)
'## ============ [1] Pound = 0.454 kgs ======================== ##
Pound_KilogramConversion = (ConvertPound_Kilogram * 0.454).ToString(DecimalPlace)
End Function
'## ===================================================== ##
Public Function Kilogram_PoundConversion(ByVal ConvertKilogram_Pound As Integer)
'## ============ [1] Kg = 2.205 Pound =========================##
Kilogram_PoundConversion = (ConvertKilogram_Pound * 2.205).ToString(DecimalPlace)
End Function
'## =====================================================##
End Class
Public Class Form107
Private Sub CalculateBtn_Click(sender As Object, e As EventArgs) Handles CalculateBtn.Click
'##=================Dimension Objects & Variables================##
'## ================Dimension Weight Conversions as Object -------------##
Dim MyPound_KilogramConversion As Object
Dim MyKilogram_PoundConversion As Object
'## ====================================================##
'## MyPercent_OriginalValue = MyClassFindOriginal_PercentageDecrementValue()---##
MyPound_KilogramConversion = New MyClassPounds_KilogramsConversion()
MyKilogram_PoundConversion = New MyClassPounds_KilogramsConversion()
'## =====================================================##
'## ========== Assign Label Error Format ==========================##
'## Reset Lbl_Answer.Text Forecolor to Blue --------------------------------------##
LblPounds_Kilograms.ForeColor = Color.Blue
LblKilograms_Pounds.ForeColor = Color.Blue
'## =====================================================##
'## ========== Assign Label Error Format ==========================##
'## Declare Lbl_ErrMsg as Invisible -----------------------------------------------##
LblErrorMessage.Visible = False
'## =====================================================##
'##============== Assign Error HANDLING ========================##
'## Try... Catch... End Try... Structure -----------------------------------------------##
'## Error Handling Routine ------------------------------------------------------##
Try
'##====================================================##
'## ==============Dimension Variables as Single Precision ===========##
Dim Pounds_Kilograms As Single
Dim Kilograms_Pounds As Single
'##====================================================##
'##============= Assign Numeric TextBox Values ==================##
'## ------------ Arithmetic Format Forms --------------------------------------##
'## Assign Numeric Values to Variables -----------------------------------------##
Pounds_Kilograms = TxtPound_Kilograms.Text
Kilograms_Pounds = TxtKilogram_Pounds.Text
## ====================================================##
'## ============Assign Value to Label.Text Weight Conversion Calculus ==================##
LblPounds_Kilograms.Text = (MyPound_KilogramConversion.Pound_KilogramConversion(Pounds_Kilograms))
LblKilograms_Pounds.Text = (MyKilogram_PoundConversion.Kilogram_PoundConversion(Kilograms_Pounds))
'##==================================================================##
'##====================Catch Non_Numeric Exception==========================##
'## Try... Catch... End Try... Structure Non_NumericInput As Exception-----------------------------------##
Catch Non_NumericInput As Exception
'##==================================================================##
'##=================Program Flow SubRoutine [1] Error Handling=====================##
'## Catch Non Numeric Input as Error --------------------------------------------------------------##
NonNumericInput()
'##==================================================================##
'##======================== End Try [Error Handling] ==========================##
End Try
'##====================================================================##
End Sub
'## =================== Error Handling Subroutine =================================##
'## Sub[1] ----------------------------------------------------------------------------------------------##
'## Error Handling Message Routine ----------------------------------------------------------------------##
Sub NonNumericInput()
LblPounds_Kilograms.ForeColor = Color.Red
LblKilograms_Pounds.ForeColor = Color.Red
LblPounds_Kilograms.Text = "Error"
LblKilograms_Pounds.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
'## ============= Clear Text & Label Boxes =====================================##
'## Clear Text and Label Boxes for Re-Evaluation -----------------------------------------------------##
LblPounds_Kilograms.Text = ""
LblKilograms_Pounds.Text = ""
TxtPound_Kilograms.Text = ""
TxtKilogram_Pounds.Text = ""
LblErrorMessage.Text = ""
'##===================================================================##
End Sub
Private Sub IndexBtn_Click(sender As Object, e As EventArgs) Handles IndexBtn.Click
'## ========= Transfer Control back to Form105 Menu ===============================##
Form105.Show()
Me.Hide()
'## ==================================================================##
End Sub
Private Sub Form107_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'## ====== Delete Label Box Names at Start up Procedure ==============================##
LblPounds_Kilograms.Text = ""
LblKilograms_Pounds.Text = ""
LblErrorMessage.Text = ""
'## ==================================================================##
End Sub
End Class