Results 1 to 3 of 3
  1. #1
    xFishx's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Location
    Michigan
    Posts
    101
    Reputation
    10
    Thanks
    27
    My Mood
    Amused

    How to make a BMI calculator

    How to create a BMI calculator, English and Metric:

    First steps:

    First you need to add 2 numeric up and down boxes to the form.
    name them numWeight and numHeight, make sure you change the maximum number in numWeight to 350 (Because it's 100 and i'm sure everyone weighs over 100 pounds.)
    Make sure for decimal places you put 2 and increment you put either 1 or .5 your choice.

    Now create two labels name weight and height, position the labels so they correspond with the correct numeric boxes.
    Now make them say Weight(Pounds) and Height(Inches).

    Next we're going to add the function that does the math for the english system. Double click your form and add this code:
    Code:
    Public Sub Calculate_english()
    
            Dim Result As Double
            Dim Rounded_Result As Double
    
            Result = numWeight.Value / (numHeight.Value * numHeight.Value) * 703 ' this is saying to take the value from the numWeight box and divide it by the numHeight value squared (numHeight*numHeight) times 703
    
            Rounded_Result = Math,Round(Result, 1) ' Rounds the result of the BMI to the first decimal. (Math,Round change the comma to a period. It was block because it thought it was an url or something.)
            bmi.Text = Rounded_Result.ToString ' This is saying that the label bmi (we'll create this later) is going to be the rounded result.
    
            BMI_Message(Rounded_Result) 'this is for the message system (underweight, etc..) we'll do the code for that later.)
        End Sub
    Next we're going to create the function for the metric system: (Note i copied and pasted this from the english function above so i didn't have to redo the colors.. so make sure everything english is changed to metric if i forgot it. DO NOT ADD * 703. THE METRIC SYSTEM FOR BMI IS DIFFERENT IT IS JUST WEIGHT DIVIDED BY HEIGHT SQUARED.
    Code:
    Public Sub Calculate_metric()
    
            Dim Result As Double
            Dim Rounded_Result As Double
    
            Result = numWeight.Value / (numHeight.Value * numHeight.Value)' this is saying to take the value from the numWeight box and divide it by the numHeight value squared (numHeight*numHeight).
    
            Rounded_Result = Math,Round(Result, 1) ' Rounds the result of the BMI to the first decimal. (Math,Round change the comma to a period. It was block because it thought it was an url or something.)
            bmi.Text = Rounded_Result.ToString ' This is saying that the label bmi (we'll create this later) is going to be the rounded result.
    
            BMI_Message(Rounded_Result) 'this is for the message system (underweight, etc..) we'll do the code for that later.)
        End Sub
    No we are going to create the message system which is to determine whether the user is underweight, overweight, normal or obese.
    Ignore the message.text we'll add label later so you may get so errors just entering this. Don't change anything unless you know what your doing.
    Code:
    Public Sub BMI_Message(ByVal BMI_Value As Double)
            Select Case BMI_Value
                Case 0.0 To 18.5 'if the BMI value is ranged from 0.0 to 18.5 then display the message "Underweight"
                    message.Text = "Underweight"
                Case 18.6 To 24.9 'if the BMI is ranged from 18.6 to 24.9 then display the message "Normal Weight"
                    message.Text = "Normal Weight"
                Case 25.0 To 29.9 'if the BMI is ranged from 25.0 to 29.9 then display the message "Overweight"
                    message.Text = "Overweight"
                Case Is >= 30.0 'if the BMI is ranged from 30.0 and above then display the message "Obese"
                    message.Text = "Obese"
                Case Else 'if the BMI is ranged with anyother number or is lower then 0 somehow or some random shit then display"unable to determine BMI result"
                    message.Text = "Unable to Determine BMI Result"
            End Select
        End Sub
    Now we're going to create 2 more labels and then name them bmi and message, and in properties change visible true to visible false. Don't worry about changing the text. the program will do that for us!

    Next we're going to create 2 radio buttons, name one english and one metric. Text for english is going to be English, and for metric it's going to be Metric. These are so the user can choose whether he wants to measure their BMI in the metric or english system.

    Double click the english radio button and add this code.
    Code:
    Private Sub english_CheckedChanged(sender As Object, e As EventArgs) Handles english.CheckedChanged
            If english.Checked Then 'if the english radio button is check then
                metric.Checked = False 'the metric radio button is not checked
                weight.Text = "Weight(Pounds)" 'weight label is going to be weight(Pounds)
                height.Text = "Height(Inches)" 'height label is going to be height(inches)
                numWeight.Value = "100"
                numHeight.Value = "50"
            End If
        End Sub
    Now double click the metric radio button and add:
    Code:
    Private Sub metric_CheckedChanged(sender As Object, e As EventArgs) Handles metric.CheckedChanged
            If metric.Checked Then 'if the metric radio button is check then
                english.Checked = False 'the english radio button is not checked
                weight.Text = "Weight(Kilograms)" 'weight label is going to be weight(kilograms)
                height.Text = "Height(Meters)" 'height label is going to be height(meters)
                numWeight.Value = "40"
                numHeight.Value = "1.00"
            End If
        End Sub
    Ok now when you debug the program when you check metric system or english system the labels should change according to which one is checked. If not then run through those codes and check for mistakes.

    Finally we are going to add a button leave the name how it is, and change the text to calculate then double click it and add this code:
    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If english.Checked = True Then
                Try
                    Calculate_english()
                    MsgBox("Your BMI (Body mass indicator) has been calculated in the English system.", MsgBoxStyle.Exclamation, "Calculated!")
                    bmi.Visible = True
                    message.Visible = True
    
                Catch ex As Exception
                    MsgBox("Error - " & ex.Message, MsgBoxStyle.Critical, "BMI Calculator Error Has occured.")
                End Try
            End If
            If metric.Checked = True Then
                Try
                    Calculate_metric()
                    MsgBox("Your BMI (Body mass indicator) has been calculated in the Metric system.", MsgBoxStyle.Exclamation, "Calculated!")
                Catch ex As Exception
                    MsgBox("Error - " & ex.Message, MsgBoxStyle.Critical, "BMI Calculator Error Has occured.")
                End Try
            End If
        End Sub
    After that Debug it and test it out!
    Have any errors or concerns post here! If i helped thank me!
    NO NEGATIVE FEEDBACK PLEASE IDC WHAT YOU THINK IF IT'S NEGATIVE..
    Never Look At Some Thing The Way It Is; You May Never Achieve It.
    Pain is only weakness leaving the body.

  2. #2
    saqib31's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Location
    In a drawer.
    Posts
    239
    Reputation
    28
    Thanks
    16
    My Mood
    Busy
    What is BMI?


    ]

  3. #3
    theboyonearth's Avatar
    Join Date
    Sep 2018
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0

    BMI Is body mass index

    Quote Originally Posted by saqib31 View Post
    What is BMI?
    It's Body Mass Index, and the guy above is talking about BMI Calculator like this : https://bmiwiki.com/bmi-calculator/

    Hope you got it.

Similar Threads

  1. [Tutorial] How to make a K/D Calculator With Details :)
    By Intellectual in forum CrossFire Tutorials
    Replies: 13
    Last Post: 07-09-2012, 09:49 PM
  2. how to make sample calculator
    By /b/oss in forum Programming Tutorials
    Replies: 11
    Last Post: 03-24-2010, 03:08 PM
  3. [TUT]How to make a Calculator
    By hopefordope in forum Visual Basic Programming
    Replies: 32
    Last Post: 03-03-2010, 12:57 PM
  4. [C++]How to make a calculator
    By HypnoticBabeTrap in forum C++/C Programming
    Replies: 5
    Last Post: 12-05-2009, 08:33 AM
  5. How to make a Basic Addition Calculator + Explenation
    By phoenixraider in forum C++/C Programming
    Replies: 4
    Last Post: 12-21-2008, 01:32 PM