Saturday, May 28, 2011

BMI CALCULATOR

This is a program which i was wrote using C and now i implement it using VB.NET.
Use to calculate Body Mass Index

Version 1.0.0.0
This is the Source:

Main form Bmicalc


' ---------------------------------------'
' Body Mass Index Calculator.            +
' A VB implementation of my C program.   +
' Created by JK CREATIONS.               +
' ---------------------------------------'

Public Class Bmicalc

    Private Sub calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calc.Click

        Dim name As String
        Dim h_in_f As Integer
        Dim h_in_i As Integer
        Dim wet As Decimal

        Dim h_in_m As Decimal
        Dim bmi As Decimal

        name = tb_name.Text

        Try
            h_in_f = tb_h_in_f.Text
            h_in_i = tb_h_in_i.Text
            wet = tb_wet.Text

        Catch ex As InvalidCastException 'Check fields for invalid inputs.

            MsgBox("Please enter details to correct fields.", vbExclamation)
            Exit Sub

        End Try

        If wet = 0 Or (h_in_f = 0 And h_in_i = 0) Then 'Check fields for null values.

            MsgBox("Height and Weight cant be zero.", vbExclamation)
            Exit Sub

        End If

        h_in_m = h_calc(h_in_f, h_in_i)
        bmi = wet / (h_in_m * h_in_m)
        bmi_chk(bmi, name)

    End Sub

    Function h_calc(ByVal h_in_f, ByVal h_in_i) As Decimal

        Dim inch As Integer

        inch = (h_in_f * 12) + h_in_i

        Return (inch / 39.37008)

    End Function

    Sub bmi_chk(ByVal bmi, ByVal name) 'Cheking the BMI

        TextBox5.Text = "" 'Cleare if there any past.

        bmi = Math.Round(bmi, 3)

        'Cheking male or female
        If male.Checked = True Then

            If bmi < 16 Then

                TextBox5.Text += "Mr: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Severely Underweight" & vbCrLf
                TextBox5.Text += "You must gain some weight !"

            ElseIf bmi >= 16 And bmi < 18.5 Then

                TextBox5.Text += "Mr: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Underweight" & vbCrLf
                TextBox5.Text += "If you gain some weight you will be much handsom !"

            ElseIf bmi >= 18.5 And bmi < 25 Then

                TextBox5.Text += "Mr: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Normal" & vbCrLf
                TextBox5.Text += "You are a Handsom Guy !"

                MsgBox("HI HANDSOM !")

            ElseIf bmi >= 25 And bmi < 30 Then

                TextBox5.Text += "Mr: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Overweight" & vbCrLf
                TextBox5.Text += "Try to reduce some weight"

            ElseIf bmi > 30 Then

                TextBox5.Text += "Mr: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Obese" & vbCrLf
                TextBox5.Text += "You are much over the limit !"

            End If

        ElseIf female.Checked = True Then

            If bmi < 15 Then

                TextBox5.Text += "Miss: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Severely Underweight" & vbCrLf
                TextBox5.Text += "You must gain some weight !"

            ElseIf bmi >= 15 And bmi < 17.5 Then

                TextBox5.Text += "Miss: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Underweight" & vbCrLf
                TextBox5.Text += "If you gain some weight you will be much pretty !"

            ElseIf bmi >= 17.5 And bmi < 24 Then

                TextBox5.Text += "Miss: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Normal" & vbCrLf
                TextBox5.Text += "You are a Pretty Girl !"

                MsgBox("HI PRETTY !")

            ElseIf bmi >= 24 And bmi < 29 Then

                TextBox5.Text += "Miss: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Overweight" & vbCrLf
                TextBox5.Text += "Try to reduce some weight"

            ElseIf bmi > 29 Then

                TextBox5.Text += "Miss: " & name & vbCrLf
                TextBox5.Text += "Your BMI Index: " & bmi & vbCrLf
                TextBox5.Text += "Your weight Category: Obese" & vbCrLf
                TextBox5.Text += "You are much over the limit !"

            End If

        ElseIf male.Checked = False And female.Checked = False Then

            MsgBox("Plese select Male Or Female", vbExclamation)

        End If

    End Sub

    Sub clrscrn() 'Clear all text boxes

        tb_h_in_f.Text = ""
        tb_h_in_i.Text = "0"
        tb_name.Text = ""
        tb_wet.Text = ""
        TextBox5.Text = ""

    End Sub

    Private Sub clr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clr.Click

        clrscrn()

    End Sub

    Private Sub xit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xit.Click

        If MsgBox("Do you realy want to Exit?", vbYesNo + vbQuestion, "Exit") = vbYes Then

            MsgBox("JK CREATIONS", vbInformation)
            End

        End If

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

        MsgBox("JK CREATIONS")
        End

    End Sub

    Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click

        'Try to open default web browser.
        Try
            System.Diagnostics.Process.Start("http://en.wikipedia.org/wiki/Body_mass_index")

        Catch ex As BadImageFormatException

            MsgBox("Cannot open web browser", vbCritical)
            Exit Sub

        End Try

    End Sub

    Private Sub optimlw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optimlw.Click

        Dim name As String
        Dim h_in_f As Integer
        Dim h_in_i As Integer
        Dim wet As Decimal

        Dim h_in_m As Decimal
        Const opt_bmi_m As Decimal = 21.75
        Const opt_bmi_w As Decimal = 20.75

        name = tb_name.Text

        Try
            h_in_f = tb_h_in_f.Text
            h_in_i = tb_h_in_i.Text

        Catch ex As InvalidCastException

            MsgBox("Please enter your height.", vbExclamation)
            Exit Sub

        End Try

        If h_in_f = 0 And h_in_i = 0 Then 'Check fields for null values.

            MsgBox("Height cant be zero.", vbExclamation)
            Exit Sub

        End If

        h_in_m = h_calc(h_in_f, h_in_i)

        TextBox5.Text = "" 'Cleare if there any past.

        If male.Checked = True Then

            wet = opt_bmi_m * h_in_m * h_in_m

            TextBox5.Text += "Your Optimal weight is:" & Math.Round(wet)

        ElseIf female.Checked = True Then

            wet = opt_bmi_w * h_in_m * h_in_m

            TextBox5.Text += "Your Optimal weight is:" & Math.Round(wet)

        Else

            MsgBox("Please select male or female", vbExclamation)

        End If

    End Sub

    Private Sub h_convert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles h_convert.Click

        height_con.Enabled = True
        height_con.ShowDialog()

    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click

        about.Enabled = True
        about.Show()
        about.Focus()

    End Sub
End Class

Second form height_con

Public Class height_con

    Dim h_in_f As Integer
    Dim h_in_i As Integer

    Private Sub calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calc.Click

        Dim h_input As Decimal

        Try
            h_input = TextBox1.Text

        Catch ex As InvalidCastException

            MsgBox("Invalid input", vbCritical)
            Exit Sub

        End Try

        If h_in_cm.Checked = True Then

            h_in_f = h_input / 30

            h_input = h_input Mod 30
            h_in_i = h_input / 2.54

        ElseIf h_in_m.Checked = True Then

            h_in_f = h_input * 10 / 3

            h_input = (h_input * 100) Mod 30
            h_in_i = h_input / 2.54

        End If

        TextBox2.Text = ""
        TextBox2.Text += "Feets: " & h_in_f & vbCrLf
        TextBox2.Text += "Inches: " & h_in_i

        send.Enabled = True
        Label2.Text = "Click Send to send values to BMI Calculator"

    End Sub

    Private Sub go_back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles go_back.Click

        Me.Close()

    End Sub

    Private Sub send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles send.Click

        Bmicalc.tb_h_in_f.Text = h_in_f
        Bmicalc.tb_h_in_i.Text = h_in_i

        Me.Close()

    End Sub
End Class

Third form about

Class about

    Private Sub about_DClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick

        Me.Close()

    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

        System.Diagnostics.Process.Start("http://jkaushalya.blogspot.com/")

    End Sub
End Class

0 comments:

Visitors Count

Free Hit Counter