|
-
Sep 11th, 2010, 10:55 AM
#1
Thread Starter
Junior Member
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
-
Sep 11th, 2010, 10:57 AM
#2
Re: Bmi Calculation Problem Code. Need Help !!
This isn't VB6 or earlier, it is some flavor of VB.Net.
-
Sep 11th, 2010, 12:12 PM
#3
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
-
Sep 11th, 2010, 12:23 PM
#4
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2010, 12:46 PM
#5
Re: Bmi Calculation Problem Code. Need Help !!
 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?
-
Sep 11th, 2010, 02:36 PM
#6
Hyperactive Member
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.
-
Sep 12th, 2010, 05:33 AM
#7
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 )
-
Sep 12th, 2010, 11:20 AM
#8
Re: Bmi Calculation Problem Code. Need Help !!
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.
-
Sep 15th, 2010, 11:54 AM
#9
Thread Starter
Junior Member
Re: Bmi Calculation Problem Code. Need Help !!
 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.
-
Oct 3rd, 2010, 07:27 AM
#10
Thread Starter
Junior Member
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]

also please fix the resize function ^^ thx for helping me ..
-
Oct 3rd, 2010, 08:20 AM
#11
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
Last edited by dbasnett; Oct 3rd, 2010 at 10:12 AM.
-
Oct 3rd, 2010, 09:29 AM
#12
Thread Starter
Junior Member
Re: Bmi Calculation Problem Code. Need Help !!
[spolier] [/spoiler]
is 't the same as this.. sorry the Photos alreday when missing
-
Oct 3rd, 2010, 09:30 AM
#13
Thread Starter
Junior Member
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]
Last edited by whitefloux90; Oct 3rd, 2010 at 09:47 AM.
Reason: Picture missing re-Post
-
Oct 3rd, 2010, 10:21 AM
#14
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.
-
Oct 3rd, 2010, 10:25 AM
#15
Thread Starter
Junior Member
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..
-
Oct 3rd, 2010, 10:39 AM
#16
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
-
Oct 3rd, 2010, 11:27 AM
#17
Thread Starter
Junior Member
Re: Bmi Calculation Problem Code. Need Help !!
-
Oct 4th, 2010, 05:27 AM
#18
Thread Starter
Junior Member
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..
-
Oct 4th, 2010, 07:56 AM
#19
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?
-
Oct 4th, 2010, 12:53 PM
#20
Thread Starter
Junior Member
Re: Bmi Calculation Problem Code. Need Help !!
ya it keeps happening by determine all the value to Underweight only..
-
Oct 4th, 2010, 12:57 PM
#21
Thread Starter
Junior Member
Re: Bmi Calculation Problem Code. Need Help !!
hope u see this picture to get the picture of what am i really doin ..
http://www.freeimagehosting.net/uplo...bc94fc34aa.jpg
or see post ...#13
-
Oct 4th, 2010, 04:40 PM
#22
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
-
Oct 4th, 2010, 07:21 PM
#23
Thread Starter
Junior Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|