Bmi Calculation Problem Code. Need Help !!
First of all, hello all^^. actually don't know whether this is a suitable place or not to post this problem.
anyway let straight to the point., actually i have a problem with this coding for my school project.
theres no error too fix but i can't get the calculation and if statement in the right thing . don't know whether the phrase or something .
a newbie like me, already think of it.. the problem hundreds of time..
try to fix it. but still the same thing happen.
BMI Code:
Public Class Form1
Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
Dim Weight, Height As Integer
Dim BMI As Integer
Weight = Val(TxtWeight.Text)
Height = Val(TxtHeight.Text)
BMI = (Weight \ Height)
If BMI < 50 Then
LblShow.Text = ("Under Weight for Your Height")
Else
LblShow.Text = ("Over Weight For You Height")
End If
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
TxtHeight.Clear()
TxtWeight.Clear()
LblShow.Text = " "
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
MessageBox.Show("Bye!!")
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Re: Bmi Calculation Problem Code. Need Help !!
This isn't VB6 or earlier, it is some flavor of VB.Net.
Re: Bmi Calculation Problem Code. Need Help !!
Whitefloux90. You will have to provide more info. What are the input values and what result are you expecting and what result did you get?
P.S. I'll notify administrator to move this thread to the .Net forums
Re: Bmi Calculation Problem Code. Need Help !!
Hello whitefloux90 :)
The two things that I see which is incorrect is
1) You have declared the variables as integer. So you will not get the value in decimals.
2) The formula for BMI is this
Re: Bmi Calculation Problem Code. Need Help !!
Quote:
Originally Posted by
koolsid
1) You have declared the variables as integer. So you will not get the value in decimals.
Sid, that may be intentional. Notice that integer division is also being used?
Re: Bmi Calculation Problem Code. Need Help !!
@whitefloux90: If you want to make that program in visual basic 6.0 then here is a link, I've found it while i was surfing. http://www.vbtutor.net/VB_Sample/bmi_calculator.htm.
It's a good link for newbies like me too.
Re: Bmi Calculation Problem Code. Need Help !!
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
(thanks for letting us know LaVolpe :thumb: )
Re: Bmi Calculation Problem Code. Need Help !!
Quote:
theres no error too fix but i can't get the calculation and if statement in the right thing .
Well, if you take a look at the BMI formula that has been linked, it's a bit obvious as to what's going on here.
You are taking the weight and height and simply dividing the two. According to the formula, you need to take the weight, multiply it by 703, then divide by the height squared:
Code:
Dim Weight As Integer = 0I
Dim Height As Integer = 0I
If Integer.TryParse(TxtWeight.Text, Weight) AndAlso Integer.TryParse(TxtHeight.Text, Height) Then
'Perform the calculations here.
Weight = Weight * 703
Height = Height * Height
Dim BMI As Integer = (Weight / Height)
'Do the check.
If BMI < 50 Then
LblShow.Text = ("Under Weight for Your Height")
Else
LblShow.Text = ("Over Weight For You Height")
End If
Something like this. Now, I didn't type this in the IDE, but in the response here. There are a few things you should look up, such as the Integer.TryParse() method. No guarantee the code will work, but you should read up on the TryParse() method so you can use it in the future.
Your code was close, but it wasn't exactly doing something right. I don't like the use of the Val() method since I see it as Legacy VB6 code, and I just changed a few things from your code to create mine. I think it'll work for you, but as I said, you weren't far off.
Re: Bmi Calculation Problem Code. Need Help !!
Quote:
Originally Posted by
formlesstree4
Well, if you take a look at the BMI formula that has been linked, it's a bit obvious as to what's going on here.
You are taking the weight and height and simply dividing the two. According to the formula, you need to take the weight, multiply it by 703, then divide by the height squared:
Code:
Dim Weight As Integer = 0I
Dim Height As Integer = 0I
If Integer.TryParse(TxtWeight.Text, Weight) AndAlso Integer.TryParse(TxtHeight.Text, Height) Then
'Perform the calculations here.
Weight = Weight * 703
Height = Height * Height
Dim BMI As Integer = (Weight / Height)
'Do the check.
If BMI < 50 Then
LblShow.Text = ("Under Weight for Your Height")
Else
LblShow.Text = ("Over Weight For You Height")
End If
Something like this. Now, I didn't type this in the IDE, but in the response here. There are a few things you should look up, such as the
Integer.TryParse() method. No guarantee the code will work, but you should read up on the TryParse() method so you can use it in the future.
Your code was close, but it wasn't exactly doing something right. I don't like the use of the Val() method since I see it as Legacy VB6 code, and I just changed a few things from your code to create mine. I think it'll work for you, but as I said, you weren't far off.
ow , phew .
thx all .
anyway as do i remembered it again this is how it look like formula
Table: Metric BMI Formula BMI =
( kg/m² ) weight in kilograms
————————————
height in meters²
and previous msges thx all fix this coding..
yet thx again all of ya
if i missing something i will repost the content back.
cause i found that this were The Codes for console application not a windows .. is't can use in windows application.
=======================================
Private Sub Command1_Click()
Label4.Caption = BMI(Text1.Text, Text2.Text)
End Sub
Private Function BMI(height, weight)
BMIValue = (weight) / (height ^ 2)
BMI = Format(BMIValue, "0.00")
End Function
========================================
thx for bringing this post to vb 2002 & later..
thx all of you.
Re: Bmi Calculation Problem Code. Need Help !!
Sry to bring this matter again could you fix this .
underweight, normal, overweight, Obese
vb Code:
[CODE]Public Class Form1
Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
Dim Weight As Integer = 0I
Dim Height As Integer = 0I
If Integer.TryParse(TxtWeight.Text, Weight) AndAlso Integer.TryParse(TxtHeight.Text, Height) Then
'Perform the calculations here.
Height = Height * Height
Dim BMI As Integer = (Weight / Height)
'Do the check.
If BMI < 18.5 Then
LblShow.Text = ("Underweight")
ElseIf BMI > 18.5 And BMI < 24.9 Then
LblShow.Text = (" Normal")
ElseIf BMI > 18.5 And BMI < 29.9 Then
LblShow.Text = (" Overweight")
Else
LblShow.Text = (" Obese")
End If
End If
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
TxtHeight.Clear()
TxtWeight.Clear()
LblShow.Text = " "
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
MessageBox.Show("Bye!!")
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BtnResult_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnResult.Resize
End Sub
End Class
[/CODE]
http://img6.glowfoto.com/images/2010...522045226L.jpg
also please fix the resize function ^^ thx for helping me ..
Re: Bmi Calculation Problem Code. Need Help !!
Code:
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Debug.WriteLine("")
For x As Integer = 0 To 11
Dim w As Double = 175
Dim myBMI As New BMIcalc(5, x, w) '5 feet, x inches, w = weight
Debug.WriteLine(myBMI.BMI.ToString("n1") & " " & myBMI.WeightStatus)
Next
Dim bmiUsingM As New BMIcalc(1.54, 80) '1.54 meter, 80 kg
Debug.WriteLine(bmiUsingM.BMI.ToString("n1") & " " & bmiUsingM.WeightStatus)
Dim bmiUsingCM As New BMIcalc(180, 80) '180 cm, 80 kg
Debug.WriteLine(bmiUsingCM.BMI.ToString("n1") & " " & bmiUsingCM.WeightStatus)
End Sub
Class BMIcalc
'adults
'(weight (lbs) / [height (in)2] x 703)
'or
'(weight (kg) / [height (m)2])
Private _height As Double
Private _weight As Double
Private _bmi As Double
Private _status As String
'height in cm (integer), weight in kg
Public Sub New(ByVal Height_in_cm As Integer, _
ByVal weight_in_kg As Double)
Me._weight = weight_in_kg
Me._height = Height_in_cm / 100
End Sub
'height in meter(double), weight in kg
Public Sub New(ByVal Height_in_m As Double, _
ByVal weight_in_kg As Double)
Me._weight = weight_in_kg
Me._height = Height_in_m
End Sub
'height in feet and inches, weight in lbs
Public Sub New(ByVal height_ft As Integer, _
ByVal height_inches As Integer, _
ByVal weight_in_lbs As Double)
'convert feet / inches to m
Me._height = height_ft * 12
Me._height += height_inches
Me._height = (Me._height * 2.54) / 100
'convert lbs to kg
Me._weight = weight_in_lbs / 2.2
End Sub
Public Function BMI() As Double
Dim hSqrd As Double = Me._height * Me._height
If hSqrd <> 0 Then Me._bmi = Me._weight / hSqrd Else Me._bmi = -1
'set status
Select Case Me._bmi
Case Is = -1
Me._status = "Error"
Case Is <= 18.5
Me._status = "Underweight"
Case Is <= 24.9
Me._status = "Normal"
Case Is <= 29.9
Me._status = "Overweight"
Case Else
Me._status = "Obese"
End Select
Return Me._bmi
End Function
ReadOnly Property WeightStatus As String
Get
Return Me._status
End Get
End Property
End Class
Re: Bmi Calculation Problem Code. Need Help !!
[spolier]http://www.glowfoto.com/static_image.../img4/glowfoto[/spoiler]
is 't the same as this.. sorry the Photos alreday when missing
Re: Bmi Calculation Problem Code. Need Help !!
@dbasnett
please click link to get the link picture..
theres a problem on seeing the picture from the previous Post.. sry.
Code:
Public Class Form1
Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
Dim Weight As Integer = 0I
Dim Height As Integer = 0I
If Integer.TryParse(TxtWeight.Text, Weight) AndAlso Integer.TryParse(TxtHeight.Text, Height) Then
'Perform the calculations here.
Height = Height * Height
Dim BMI As Integer = (Weight / Height)
'Do the check.
If BMI < 18.5 Then
LblShow.Text = ("Underweight")
ElseIf BMI > 18.5 And BMI < 24.9 Then
LblShow.Text = (" Normal")
ElseIf BMI > 18.5 And BMI < 29.9 Then
LblShow.Text = (" Overweight")
Else
LblShow.Text = (" Obese")
End If
End If
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
TxtHeight.Clear()
TxtWeight.Clear()
LblShow.Text = " "
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
MessageBox.Show("Bye!!")
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BtnResult_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnResult.Resize
End Sub
End Class
[img=http://www.freeimagehosting.net/uploads/th.bc94fc34aa.jpg]
Re: Bmi Calculation Problem Code. Need Help !!
@whitefloux90 - Make the following the first line of your program
Option Strict On
Take a look at the code I posted in post #11.
Re: Bmi Calculation Problem Code. Need Help !!
may i know which 1 is strict ON
is't at the public form or at the private sub button2.click?
sry i trouble u..
Re: Bmi Calculation Problem Code. Need Help !!
Code:
Option Strict On ' Here
Public Class Form1
Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
End Sub
End Class
Re: Bmi Calculation Problem Code. Need Help !!
Re: Bmi Calculation Problem Code. Need Help !!
@dbasnet
Excuse me, what was that again.. cuz i already place it and i run error output. come it be like that?
the real after + my code it when true like ?
sry , i'm too newbie on this world..
Re: Bmi Calculation Problem Code. Need Help !!
The errors you get when you have Option Strict On should be fixed. Those errors are part of the problem you are having. Did you try the code I posted? Did it have errors?
Re: Bmi Calculation Problem Code. Need Help !!
ya it keeps happening by determine all the value to Underweight only..
Re: Bmi Calculation Problem Code. Need Help !!
Re: Bmi Calculation Problem Code. Need Help !!
Are 18.5, 24.9, or 29.9 integers?
Did you look at the code I posted? Did you try the code I posted?
Did you fix the errors Option Strict On showed? If so please re-post the code you have.
Please do not duplicate posts
http://www.vbforums.com/showthread.php?t=629487
Re: Bmi Calculation Problem Code. Need Help !!
@dbasnett : ow , sorry. yah problem solve already with your code. thx for teaching me use Option Stric On.^^ Rep
+1