Introduction: BMI Calculator

My name is Umair Bin Asim. I am a student of Global Perspective, doing my O levels. This project is part of an awareness campaign that me and my classmates are currently conducting. We recognize obesity as a rising problem all over the world and are encouraging people to combat obesity before it leads to a major social catastrophe. This project is one of our many awareness campaigns.

The BMI calculator, is to allow people more ease in calculating their body mass index and determining whether or not they are obese. The calculator we've made is set in the standards of the american health association. The purpose of posting this is to allow people to not only make a calculator but to also allow people to modify their calculators to whatever their national standard is.

Step 1: Creating a New Visual Studio Project

  1. open visual studio
  2. click on new project
  3. select widows form application
  4. rename the project to "BMI calculator"
  5. save the project and remember the location (i've saved it in a separate drive)

Step 2: Two Sections

there two sections in Visual studio windows form application

1) Form1.vb [Design]

in here you create the GUI

2) Form1.vb

in here you write your programming

you can choose the tabs by selecting on them

Step 3: Design the Interface (labels and Textboxes)

in this step you need to design the graphics user interface.

  1. select labels from the toolbox available (if you cannot find the tool box press Ctrl+Alt+x)
  2. drag the label on to the form and arrange them on the right. we need three labels
  3. arrange the labels along the left
  4. click on the labels and in the properties change Autosize to FALSE, this will allow you to resize the label.
  5. click on the labels and in the properties change the text to "height","weight","your BMI ", respectively.

  6. you can also change other setting in properties such as colour and 3D effect.

  7. drag three text boxes from the toolbox and align them along the left parallel to the labels

  8. click on the textbox and in the properties change the name settings to "txtheight", "txtweight", "txtresults"

  9. you can also change other setting in properties such as colour and 3D effect.

  10. create a last textbox and align it on the bottom, name this text box "txtcomment", this will give a result on the basis of the persons BMI as understanding from numbers alone may be difficult.

  11. changing the name is essential as we will have to call these textboxes up in our program, if you prefer to put any other name you must change the name of the referred button in the program as well. (the names are according to my program)

Step 4: Design the Interface (buttons)

place buttons by dragging them from the toolbox and aligning them as show in picture

while the button is selected change the name on the button in the properties, and you can change the text setting too.

  • create a button name "btncalc", with text "calculate BMI"
  • create a button name "btnclear", with text "clear"
  • create a button name "btnexit", with text "exit"
  • create a button name "btnabout", with text "learn about us"
  • create a button name "btnhlp", with text "need help?" (i haven't used this and it's been left free in case you want to add a help button)

align the buttons in the GUI form as you see fit

changing the name is essential as we will have to call these buttons up in our program, if you prefer to put any other name you must change the name of the referred button in the program as well. (the names are according to my program)

Step 5: Programming Your Calculator

Public Class Form1
    Private Sub btncalc_Click(sender As System.Object, e As System.EventArgs) Handles btncalc.Click
        Dim height As Double = 0 'creates variable named height
        Dim weight As Double = 0 'creates variable named weight
        Dim BMI As Double = 0 'creates variable named BMI
        txtresults.Text = ""
        height = Double.Parse(txtheight.Text) 'reads numerals from text box txtheight and saves it into respective variable
        weight = Double.Parse(txtweight.Text) 'reads numerals from text box txtweight and saves it into respective variable
        height = height * 0.0254 'converts height into meters
        weight = weight * 0.4535924 'converts weight into kilograms
        height = height * height 'squares helght and saves it into variable height
        If ((height <= 0) Or (weight <= 0)) Then 'validity check to ensure unnatural data is not entered
            cleanup()
            MsgBox("please insert realistic values")
            Exit Sub
        End If
        BMI = weight / height 'calculation of BMI
        BMI = Format(BMI, "0.00") 'writes BMI to two decimal placee
        txtresults.Text = BMI 'writes BMI in textbox txtresults
        txtcomment.Text = "" 'empties textbox comment to allow data entry
        'calculates condition according to BMI
        If BMI < 18.5 Then 'condition may vary in your country
            txtcomment.Text = "you are under weight"
        ElseIf ((BMI >= 18.5) And (BMI <= 24.9)) Then
            txtcomment.Text = "you are healthy, this BMI is considered normal"
        ElseIf ((BMI > 24.9) And (BMI <= 29.9)) Then
            txtcomment.Text = "you are overweight, please take precaution"
        ElseIf BMI > 29.9 Then
            txtcomment.Text = "you are obese, please take precautions"
        End If
    End Sub
    Private Sub btnexit_Click(sender As System.Object, e As System.EventArgs) Handles btnexit.Click
        Close() 'function for exit
    End Sub
    
    Private Sub btnclear_Click(sender As System.Object, e As System.EventArgs) Handles btnclear.Click
        
        cleanup() 'calls sub routine cleanup
    End Sub
    Sub cleanup() 'clears each textbox 
        txtcomment.Text = ""
        txtheight.Clear()
        txtweight.Clear()
        txtresults.Text = ""
        txtheight.Focus()
    End Sub
    Private Sub btnabout_Click(sender As System.Object, e As System.EventArgs) Handles btnabout.Click
        'this is the message shown in a separate msgbox
        'you can add any thing you want after the "=" sign below but it must be between double commas ("")
        Dim message As String = "This Software Was Made By Umair Bin Asim For The Sake Of Social Awareness On Health." & vbNewLine & " A World Wide Increase In The Number Of Obese People Has Stirred A Health Panic As The Number Of Cases Of Heart Diseases And Diabetes Are On The Rise." & vbNewLine & " Despite All This A Large Number Of People Do Not Know Whether Or Not They Are Obese Or How To Counter It." & vbNewLine & "In Response To That We Have Made A Calculator To Determine Your BMI And Whether Or Not You Are Obese." & vbNewLine & "These Standards Are According To The American Heart Association."
        MsgBox(message)
    End Sub
    Private Sub btnhlp_Click(sender As System.Object, e As System.EventArgs) Handles btnhlp.Click
        'add any message you want to write in between the ""
        ' it is empty for now
        Dim urgent_message As String = ""
        MsgBox(urgent_message)
    End Sub
    
End Class

Step 6: Congratulations Your Progamming Is Done

now you can calculate your BMI and you know how to edit your software to your liking

to play the software press the green arrow on the upper bar or simply press F5 enjoy!

for your convenience we've posted our own calculator(ready made) as well as the programming(in a .txt file)