Results 1 to 23 of 23

Thread: Bmi Calculation Problem Code. Need Help !!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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:
    1. Public Class Form1
    2.  
    3.     Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
    4.  
    5.  
    6.         Dim Weight, Height As Integer
    7.         Dim BMI As Integer
    8.  
    9.  
    10.  
    11.         Weight = Val(TxtWeight.Text)
    12.         Height = Val(TxtHeight.Text)
    13.  
    14.         BMI = (Weight \ Height)
    15.  
    16.         If BMI < 50 Then
    17.             LblShow.Text = ("Under Weight for Your Height")
    18.         Else
    19.             LblShow.Text = ("Over Weight For You Height")
    20.  
    21.         End If
    22.  
    23.  
    24.  
    25.     End Sub
    26.  
    27.     Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
    28.         TxtHeight.Clear()
    29.         TxtWeight.Clear()
    30.         LblShow.Text = " "
    31.  
    32.     End Sub
    33.     Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
    34.  
    35.         MessageBox.Show("Bye!!")
    36.  
    37.         Me.Close()
    38.  
    39.     End Sub
    40.  
    41.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    42.  
    43.     End Sub
    44. End Class

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Bmi Calculation Problem Code. Need Help !!

    This isn't VB6 or earlier, it is some flavor of VB.Net.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Bmi Calculation Problem Code. Need Help !!

    Quote Originally Posted by koolsid View Post
    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    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.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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 )

  8. #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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    Re: Bmi Calculation Problem Code. Need Help !!

    Quote Originally Posted by formlesstree4 View Post
    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.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    Re: Bmi Calculation Problem Code. Need Help !!

    Sry to bring this matter again could you fix this .
    underweight, normal, overweight, Obese

    vb Code:
    1. [CODE]Public Class Form1
    2.  
    3.     Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnResult.Click
    4.  
    5.  
    6.         Dim Weight As Integer = 0I
    7.         Dim Height As Integer = 0I
    8.         If Integer.TryParse(TxtWeight.Text, Weight) AndAlso Integer.TryParse(TxtHeight.Text, Height) Then
    9.  
    10.             'Perform the calculations here.
    11.  
    12.  
    13.             Height = Height * Height
    14.             Dim BMI As Integer = (Weight / Height)
    15.  
    16.  
    17.  
    18.  
    19.  
    20.             'Do the check.
    21.             If BMI < 18.5 Then
    22.                 LblShow.Text = ("Underweight")
    23.             ElseIf BMI > 18.5 And BMI < 24.9 Then
    24.                 LblShow.Text = (" Normal")
    25.             ElseIf BMI > 18.5 And BMI < 29.9 Then
    26.                 LblShow.Text = (" Overweight")
    27.             Else
    28.                 LblShow.Text = (" Obese")
    29.  
    30.             End If
    31.  
    32.         End If
    33.  
    34.  
    35.  
    36.  
    37.     End Sub
    38.  
    39.     Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
    40.         TxtHeight.Clear()
    41.         TxtWeight.Clear()
    42.         LblShow.Text = " "
    43.  
    44.     End Sub
    45.     Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
    46.  
    47.         MessageBox.Show("Bye!!")
    48.  
    49.         Me.Close()
    50.  
    51.     End Sub
    52.  
    53.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    54.  
    55.     End Sub
    56.  
    57.     Private Sub BtnResult_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnResult.Resize
    58.  
    59.     End Sub
    60. End Class
    61. [/CODE]


    also please fix the resize function ^^ thx for helping me ..

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    Re: Bmi Calculation Problem Code. Need Help !!

    [spolier][/spoiler]
    is 't the same as this.. sorry the Photos alreday when missing

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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..

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    Re: Bmi Calculation Problem Code. Need Help !!

    oow that 1
    gee thx...

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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..

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    Re: Bmi Calculation Problem Code. Need Help !!

    ya it keeps happening by determine all the value to Underweight only..

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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


  22. #22
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    26

    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
  •  



Click Here to Expand Forum to Full Width