top of page

The Code

Public Class Form64

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

    Dim h As Single
    Dim
w As Single
    Dim
DecimalPlace As String = "n2"

    '## 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

    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()

    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(DecimalPlace)
    End Sub

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

        If Label1.Text <= 18.5 Then : Label2.Text = "Under Weight"
        End If
        If
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

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

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

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

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


        Form57.Show()
        Me.Hide()


    End Sub


End Class

Website Links-173.jpg
bottom of page