Pages

Sunday, June 23, 2013

How to Create a BMI Calculator

How to Create a BMI Calculator

Creating a BMI calculator that will display your Body Mass Index on your computer rather than having to use an online version or doing the math by hand requires a minimum knowledge of programming and access to programming software, such as Visual Basic, Visual Basic.Net or a more complicated language. For the lay user, the free Microsoft Visual Basic Express is one way to create this calculator.

Instructions

    1

    Open Visual Basic Express, click on "New project," select "Windows application" as the type, name it "BMI Calculator" and click "OK." Change the Text property of the form in the Properties panel on the bottom right of the screen to "BMI Calculator."

    2

    Create two labels on the form that appears by double-clicking on the label tool in the toolbox on the left, identified with a large "A" and then repeating this process. Click and drag each label now on the form so that one appears under the other.

    3

    Create two text boxes in the same way, this time double-clicking on the "Textbox" tool. Place one box next to each label. Create a command button by double-clicking on the "Button" tool and place it below the labels.

    4

    Create a third label as in Step 2 and locate it next to the command button. Set the size of the first two labels in the Properties panel on the right of the screen using a width of 180 and a height of 25. Keep the third label the same height, but make the width 150.

    5

    Change the text property of the top label to read "Enter your weight in pounds" and the text property of the second label to read "Enter your height in inches." Delete the text for the third label and make the name "BMIResult." Change the text property of the command button to read "Calculate."

    6

    Double-click on the "Calculate" button to open the code window and enter the following code between the "Private sub" and "End sub" lines:
    Dim BMI As Single
    Dim Height As Short
    Dim Weight As Short
    Height = CShort(Text2.Text)
    Weight = CShort(Text1.Text)
    BMI = (Weight / (Height_Renamed * Height_Renamed)) * 703
    BMI = CSng(BMI)
    BMIResult.Text = "Your BMI is " & BMI.ToString("F1")

    7

    Test the program by pressing "F5" on the function keys. The result should pop up in the blank space next to "Calculate." If it does, press "CTRL + S" to Save. If not, go back and check the coding and names of the labels. Then click "Build." Pin the resulting EXE file to the Start menu or copy it to the Desktop.

0 comments:

Post a Comment