top of page

The Code 

 

Public Class Form1

    '## 17. Creating Functions ##
    '## Dimension Variables in Public Class Mode ##
    '## Dimension BMI Variables ##

    Dim h As Single


    Dim w As Single
    
   
'## Dimension Area Formula Variables ##
    '## Dimension Area Formula Variables ##

    Dim Length As Single = 100
    Dim
Wdth As Single = 200
    Dim
N As String = "n2"     '## Defines No. Decimal Place ##

    '## User-Defined Functions ##
    '## A Function is similar to a Sub Procedure. Both are Called by the Main Program
    'to fulfil Certain Tasks. However, there is one difference, a Function returns a Value
    'whilst a Sub Procedure does not. It merely performs a Certain Job. There are Two Types
    'of Functions, the Built-in Functions, and the User-Define Function.

    '## User Define Function - Body Mass Index Calculus ##


    Private Function BodyMassIndex(height As Single, weight As Single) As Double
        BodyMassIndex = (
weight / (height ^ 2))
    End Function

    '## User Define Function - Area Formula Calculus ##
    Private Function CalculateArea(Length As Single, Width As Single) As Double
        CalculateArea =
Length * Width
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

       '## Sub Procedure(1) ##
        AssignBMIvalues()

        '## Sub Procedure (2) ##
        AssignBMIlabel()

        '## Sub Procedure(3) ##
        WeightClassDistribution()

        '## Sub Procedure(4) ##
        AssignAreaLabel()

       End Sub

    '## Sub(1) ##
    Sub AssignBMIvalues()
       
h = Val(TextBox1.Text)
       
w = Val(TextBox2.Text)
    End Sub

    '## Sub(2) ##
    Sub AssignBMIlabel()
       
Label1.Text = BodyMassIndex(h, w).ToString(N)
    End Sub

    '## Sub(3) ##
    Sub WeightClassDistribution()

        If Label1.Text <= 18.5 Then : Label2.Text = "Under Weight"
        End If
        I
f Label1.Text >= 18.5 And Label1.Text <= 24.9 Then : Label2.Text = "Normal Weight"
        End If
        If
Label1.Text >= 25 And Label1.Text <= 29.9 Then : Label2.Text = "Over Weight"
        End If
        If
Label1.Text >= 30 Then : Label2.Text = "Obesity"
        End If

    End Sub

    '## Sub(4) ##
    Sub AssignAreaLabel()
       
'## Private Function ABC() ##
        Label3.Text = CalculateArea(Length, Wdth)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        TextBox1.Text = ""
       
TextBox2.Text = ""

        Label1.Text = ""
       
Label2.Text = ""
       
Label3.Text = ""

    End Sub


End Class

Website Links-173.jpg
bottom of page