Tuesday, 29 December 2009

BMI calculator coding

I am at this moment in time re-doing the layout for digital-damita.net with some new tips I have learnt (I hope!!), I have been researching different plug-ins and doing my normal researching of all the different blogs I know off (go to one of my favourite websites then visit all their links choose one and visit theirs, etc etc), I am also changing my style of this website, I think as well as my normal rubbish about my own personal life, I will be including reviews/research/tips regarding being green and being frugal (both I am very passionate about) and of course computer/internet related programs/websites.

Since I seem to be getting a lot of hits regarding my very old BMI calculator in visual basics, one I did about erm three years ago know, I thought I would put up the coding, so here you go google searchers.

Welcome Form

Private Sub ExitButton_Click()

Unload Me ''''''''''''''''This line of coding allows the program to close down

End Sub



Private Sub ImperialButton_Click()

Unload Me

Imperial.Show ''''''''''''''''This line of coding allows the user to enter the Imperial screen by clicking on the button

End Sub

Imperial Form



Private Sub MetricButton_Click()

Unload Me

Metric.Show ''''''''''''''''This line of coding allows the user to enter the Metric screen by clicking on the button

End Sub

Private Sub BackButton_Click()

Unload Me

Welcome.Show

End Sub

Private Sub Calculate_Click()



StonesTotal = Val(StonesBox.Text) * 14 ''''''''' This calculates the total stones by multiplying the total in the text box by the total number of pounds in a stone 14



StonesPounds = StonesTotal + Val(PoundsBox.Text) ''''''' This calculates the total pounds by adding the value calculated in StonesTotal by the amount entered into the pounds box



WeightTotal = StonesPounds * StonesPounds ''''''' This calculates the total weight by multiplying the total stones and pound by itself



FeetTotal = Val(FeetBox.Text) * 12 ''''''''' This calculates the total feet by multiplying the total in the text box by the total number of inches in a foot 12



HeightTotal = FeetTotal + Val(InchesBox.Text) ''''''' This calculates the total inches by adding the value calculated in FeetTotal by the amount entered into the inches box



TotalSum = WeightTotal / HeightTotal '''''' This calculates the total sum by taking the weight total and dividing it by the height total



Sum = TotalSum * 703 ''''' The BMI result is then worked out by the TotalSum is multiplied by 703



BMIResult.Text = Sum '''' This line of coding puts the answer into the BMI Result label



End Sub



Private Sub Reset_Click() ''''' This button allows the user to reset all the totals to 0

StonesTotal = 0

StonePounds = 0

WeightTotal = 0

HeightTotal = 0

FeetTotal = 0

TotalSum = 0

Sum = 0

BMIResult.Text = 0

PoundsBox.Text = 0

StonesBox.Text = 0

FeetBox.Text = 0

InchesBox.Text = 0

End Sub

Metric Form



Private Sub BackButton_Click()

Unload Me

Welcome.Show

End Sub



Private Sub Calculate_Click()



HeightTotal = Val(Heightbox.Text) * Val(Heightbox.Text) '''' This calculates the total height value by multiplying the value entered into height by itself



WeightTotal = Val(Weightbox.Text)  '''' This puts the value entered into the weight box into its variable



Sum = WeightTotal / HeightTotal  '''' This calculates the BMI result by dividling the weight total by the height total



BMIResult.Text = Sum '''' This line of coding puts the answer into the BMI Result label



End Sub



Private Sub Reset_Click() '''' This button allows the user to reset all the totals to 0

Heightbox.Text = 0

Weightbox.Text = 0

BMIResult.Text = 0

HeightTotal = 0

WeightTotal = 0

Sum = 0

End Sub

I have zipped it up as well you can download it here.

I will also upload my help guide on how to creating programs in visual basics later today.

No comments:

Post a Comment