Shane Partridge
Visual Basic 2013
The Code
Earth's Radius = 6,371 km
Earth's Volume = (Cubic km) = km^3
1 Trillion
83 Billion
642 Million
907 Thousand
17.52 Km^3
Public Class MyClassMultiply_FormulaApplications
'## [1]Encapsulation - Self Contained Modules ------------------------------------##
'## [2]Inheritance - Structured Class to be passed by Hierarchy Inheritance ---------##
'## Inheritance lets you focus on adding unique application features.You don't -----##
'## have to keep reinventing the wheel by rewriting existing code repeatedly. -----##
'## [3]Polymorphism - Modules represent Real World Objects known as Classes-##
'## =========Multiply_Formula Applications ==================== ##
'## Public Class Module MyClassMultiply_FormulaApplications ##
'## ------Contains a List of Formula Applications----------- ##
'## -- Class Modules can be used for Program Applications -- ##
'## ===== =Decimal Place Precision [2] ============ ##
Dim DecimalPlace as string = "n2"
'## ===================================== ##
'## ============== Area of Square Formula ======= ##
'## -------- Area of Square = 6 x (Side^2) ----------------- ##
'## ------- Using [ToString(DecimalPlace)] ----------------- ##
'## ------ Dimension Side as Single Precision -------------- ##
Public Function AreaSquare_Formula(ByVal Side as Single)
AreaSquare_Formula = (6 * (Side ^ 2)).ToString(DecimalPlace)
End Function
'## ===================================== ##
'## ============== Volume of Sphere ====================== ##
'## ------- Volume of Sphere = ((4/3) * (PI) * (Radius ^3 )) ------------------ ##
'## ------- Value of [PI] = 3.14 or [22/7] ------------------------------------##
Public Function SphereVolume_Formula(ByVal Radius as Single)
SphereVolume_Formula = ((4 / 3) * (22 / 7) * (Radius ^ 3)).ToString(DecimalPlace)
End Function
'## ================================================= ##
'## ============= Surface Area of Sphere ================ ##
'## --------- Surface Area = ((4) * (PI) * (Radius ^ 2)) ----------------- ##
'## ------- Value of [PI] = 3.14 or [22/7] ------------------------------ ##
Public Function SurfaceAreaSphere_Formula(ByVal Radius as Single)
SurfaceAreaSphere_Formula = ((4) * (22 / 7) * (Radius ^ 2)).ToString(DecimalPlace)
End Function
'## ============================================= ##
End Class
Public Class Form109
Private Sub CalculateBtn_Click(sender As Object, e As EventArgs) Handles CalculateBtn.Click
'## =========== Dimension Objects and Variables ===================##
'## ==== Dimension Square Formula as Object ========================##
Dim MySphereVolume_Formula As Object
'## =====================================================##
'## MySphereVolume_Formula = MyClassMultiply_FormulaApplications ##
MySphereVolume_Formula = New MyClassMultiply_FormulaApplications()
'## =====================================================##
'## ========== Assign Label Error Format ======================##
'## Reset Lbl_Answer.Text Forecolor to Blue ---------------------------------##
LblVolumeofSphere.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 Side as Single ===========================##
Dim Radius As Single
'# -----Assign Variable to TextBox Input ------------------------------------------#
Radius = TxtRadiusofSphere.Text
'##======================================================##
'## ===== Assign Value to Label.Text for Area Calculus =================== ##
LblVolumeofSphere.Text = (MySphereVolume_Formula.SphereVolume_Formula(Radius))
'## ==================================================== ##
'##============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()
LblErrorMessage.Visible = True
LblErrorMessage.ForeColor = Color.Red
LblErrorMessage.Text = "One of the entries is not a number! Try again!"
'##---------------------------------------------------------------##
LblVolumeofSphere.ForeColor = Color.Red
LblVolumeofSphere.Text = "Error"
'## ===========================================##
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 ----------------------##
TxtRadiusofSphere.Text = ""
LblVolumeofSphere.Text = ""
LblErrorMessage.Text = ""
'##=============================================##
End Sub
Private Sub Form109_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'## ============= Initial Startup at Form109 ================ ##
'## -----Clear Label & Text Box used in Design Mode Configuration-------- ##
LblVolumeofSphere.Text = ""
LblErrorMessage.Text = ""
'## ===============================================##
End Sub
Private Sub Index105Btn_Click(sender As Object, e As EventArgs) Handles Index105Btn.Click
'## ========= Transfer Control back to Form105 Menu =================##
Form105.Show()
Me.Hide()
'## ====================================================##
End Sub
End Class