| Home  |  | About  |  | Contact  |  | Board index » Other script » US Navy Body fat calculator 
Register  |   FAQ   |  Search  |  Login
Host : WEBHOSTINGPAD.COM
  • Free domain name
  • Unlimited Disk Space
  • Unlimited Bandwidth
  • Unlimited sub domain
  • Host unlimited domain
  • Unlimited MySql database
  • Unlimited Parked Domains
  • SSI (Server Side Includes)
  • Weekly Backups
  • And much more..
  • 1.99 USD per month

Visit : webhostingpad.com

Hosting: Free trial
FatCow is one of the leading webhost in the internet today. FatCow Web Hosting. Free Trial , Free Setup, Free Support, All risk free!
Visit: FatCow.com


Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Code conversion in VB.NET
PostPosted: Fri Feb 26, 2010 4:24 pm 
Offline
Site Admin

Joined: Wed Nov 05, 2008 8:04 am
Posts: 90
Upon request from one of my viewer I convert US Navy Body fat calculator script into VB.NET. But in my opinion if PHP is not installed on your server then JavaScript is the best alternative.
Code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="vbscript">
Protected Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        On Error Resume Next
        Dim ht As Single
        Dim nk As Single
        Dim wa As Single
        Dim hp As Single
        Dim wt As Single
        Dim ag As Integer
        Dim sexf As Boolean
        Dim bstate As Boolean
        Dim fat_ow As Integer
        Dim fat_ob As Integer
        Dim BMR As Single
        Dim fatpercent As Single
        Dim dailyCal As Single
        Dim BMI As Single

        ht = CInt(intHeight.Text)
        nk = CInt(intNeck.Text)
        wa = CInt(intWaist.Text)
        hp = CInt(intHip.Text)
        wt = CInt(intWeight.Text)
        ag = CInt(intAge.Text)

        For Each TextBox In Me.Controls
            TextBox.bordercolor = Drawing.Color.Silver
        Next

        If ((ht) = 0) Then errMsg(intHeight)
        If ((nk) = 0) Then errMsg(intNeck)
        If ((wa) = 0) Then errMsg(intWaist)
        If ((wt) = 0) Then errMsg(intWeight)
        If ((ag) = 0) Then errMsg(intAge)
        sexf = (strGender.Items(1).Selected)
        If (((hp) = 0) And sexf) Then errMsg(intHip)

        If ((ht = 0) Or (nk = 0) Or (ag = 0) _
        Or (wa = 0) Or (wt = 0)) = True Then
            MsgBox("Incomplete data!", MsgBoxStyle.DefaultButton1, "Calculator")
            Exit Sub
        End If

        If ((hp = 0) And sexf) Then
            MsgBox("Incomplete data!", MsgBoxStyle.DefaultButton1, "Calculator")
            Exit Sub
        End If

        If opHeight.Items(1).Selected Then ht = ht * 2.54
        If opNeck.Items(1).Selected Then nk = nk * 2.54
        If opWast.Items(1).Selected Then wa = wa * 2.54
        If opHip.Items(1).Selected Then hp = hp * 2.54
        If opWeight.Items(1).Selected Then wt = wt * 0.4536
        BMI=Math.Round((wt*10000/(ht*ht)),1)
        bstate=True
        fat_ow=18
        fat_ob=25
        if sexf Then
            fat_ow=25
            fat_ob=31
            BMR=Math.Round(655+(9.6*wt)+(1.8*ht)-(4.7*ag),1)
            fatpercent=Math.Round(495/(1.29579 - 0.35004 * (Math.Log10(wa + hp - nk)) + 0.221 * (Math.Log10(ht))) - 450,1)
        Else
            BMR=round(66 + (13.7 * wt) + (5 * ht) - (6.8 * ag),1)
            fatpercent=Math.Round(495 / (1.0324 - 0.19077 * (Math.Log10(wa - nk)) + 0.15456 * (Math.Log10(ht))) - 450,1)
        End if
        If Err.Number = 5 Then
            MsgBox("Invalid data!", MsgBoxStyle.DefaultButton1, "Error")
            Exit Sub
        Else
            Err.Clear()
        End If
        If opActivity.Item(0).Selected Then
            dailyCal = BMR * 1.2
        End If

        If opActivity.Item(1).Selected Then
            dailyCal = BMR * 1.375
        End If

        If opActivity.Item(2).Selected Then
            dailyCal = BMR * 1.55
        End If

        If opActivity.Item(3).Selected Then
            dailyCal = BMR * 1.725
        End If

        If opActivity.Item(4).Selected Then
            dailyCal = BMR * 1.9
        End If
        Dim w1
        Dim s1
        If BMI < 18 Then
           w1=(18*ht*ht/10000)-wt
           s1="You are underweight by "
        Else
           If fatpercent<fat_ow Then
              s1="Your weight is normal."
              bstate=false
           Else
              w1 = wt*(fatpercent - fat_ow) / (100 - fat_ow)
              s1=(IIf(fatpercent >= fat_ob, "Your weight state is Obes. You should reduce your weight by ","You are Overweight by ")
           End if
        End if
        If bstate Then s1=s1 & IIf(opWeight.Items(1).Selected, Math.Round(w1/0.4536,1) & " Pound.",Math.Round(w1,1) & " Kg.")
        Dim output="Your BMR is: " & BMR & Chr(13) & "Your BMI is: " BMI & Chr(13) & "Minimum Calorie requirement is: " & Math.Round(dailyCal)
        output=output & Chr(13) & "Your Body Fat is " & fatpercent & "%" & Chr(13) & s1
        result.Text=output
End Sub
Private Sub errMsg(ByRef txt As TextBox)
        txt.BorderColor = Drawing.Color.Red
        txt.Text = ""
        result.Text = "Enter correct data in Red box!"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>US Navy Body fat calculator</title>
<style type="text/css">
#cal_frm td, #cal_frm input{font-family: Georgia, "MS Serif", "New York", serif;font-size:12px;line-height:150%;}
.cal_text{width:97%;font-size:11px;height:16px;border:none;}
.cal_text:hover{background:#f2f2f2;}
.cal_option{width:100%;font-size:11px;border:none;}
.cal_button{height:20px; border:1px solid gray; background:#dddddd; font-size:11px; font-family:tahoma;}
#feedback input{border:1px solid gray; width:90%;}
table#cal_data{border-collapse:collapse;width:270px;margin:10px 0 0 0;}
#cal_data td{border:solid 1px gray;height:20px;padding:0;width:33%;}
</style>
</head>
<body>
<form id="cal_frm" style="width:400px; margin:20px 10px 20px 10px;" runat="server">
<h1 style="color:#444444; font-size:16px; font-family:arial; border-bottom:1px solid #777777;padding-bottom:2px; margin-bottom:15px;">US Navy Body fat calculator</h1>
<table style="width:400px; margin:0px 10px 20px 10px;">
<tr><td style="width: 275px;">
<table id="cal_data">
<tr>
<td style="padding-left:5px;">Height:</td>
<td><asp:TextBox ID="intHeight" runat="server" CssClass="cal_text"></asp:TextBox></td>
<td><asp:DropDownList ID="opHeight" CssClass="cal_option" runat="server">
<asp:ListItem Selected="True">Cm</asp:ListItem><asp:ListItem>Inch</asp:ListItem></asp:DropDownList></td></tr>
<tr>
<td style="padding-left:5px;">Neck:</td>
<td><asp:TextBox ID="intNeck" runat="server" CssClass="cal_text"></asp:TextBox></td>
<td><asp:DropDownList ID="opNeck" CssClass="cal_option" runat="server">
<asp:ListItem Selected="True">Cm</asp:ListItem><asp:ListItem>Inch</asp:ListItem></asp:DropDownList></td></tr>
<tr>
<td style="padding-left:5px;">Waist:</td>
<td><asp:TextBox ID="intWaist" runat="server" CssClass="cal_text"></asp:TextBox></td>
<td><asp:DropDownList ID="opWaist" CssClass="cal_option" runat="server">
<asp:ListItem Selected="True">Cm</asp:ListItem><asp:ListItem>Inch</asp:ListItem></asp:DropDownList></td></tr>
<tr>
<td style="padding-left:5px;">Hip (Female):</td>
<td><asp:TextBox ID="intHip" runat="server" CssClass="cal_text"></asp:TextBox></td>
<td><asp:DropDownList ID="opHip" CssClass="cal_option" runat="server">
<asp:ListItem Selected="True">Cm</asp:ListItem><asp:ListItem>Inch</asp:ListItem></asp:DropDownList></td></tr>
<tr>
<td style="padding-left:5px;">Weight:</td>
<td><asp:TextBox ID="intWeight" runat="server" CssClass="cal_text"></asp:TextBox></td>
<td><asp:DropDownList ID="opWeight" CssClass="cal_option" runat="server">
<asp:ListItem Selected="True">Kg</asp:ListItem><asp:ListItem>Pound</asp:ListItem></asp:DropDownList></td></tr>
</table>
</td>
<td style="padding: 10px 0 0 10px;">Gender:<br />
<asp:DropDownList ID="opGender" CssClass="cal_option" style="width:72%;border: solid 1px silver;" runat="server">
<asp:ListItem Selected="True">Male</asp:ListItem><asp:ListItem>Female</asp:ListItem></asp:DropDownList><br /><br />
Age:<br />
<asp:TextBox ID="txtAge" CssClass="cal_text" style="width:60%;border: solid 1px silver;"></asp:TextBox> yrs.</td></tr>
<tr>
<td colspan="2" style="padding:10px 0 10px 0;"><span style="padding:0 2px;">Activity:</span>
<asp:DropDownList ID="opActivity" CssClass="cal_option" style="width:80%; border:1px solid silver;" runat="server">
<asp:ListItem Selected="True">Sedentary (Very little or no exercise)</asp:ListItem>
<asp:ListItem>Lightly active (light exercise/sports 1-3 days/week)</asp:ListItem>
<asp:ListItem>Moderately active (moderate exercise/sports 3-5 days/week)</asp:ListItem>
<asp:ListItem>Very active (hard exercise/sports 6-7 days a week)</asp:ListItem>
<asp:ListItem>Extra active (very hard exercise/sports & physical job or 2x training)</asp:ListItem>
</asp:DropDownList></td></tr>
<tr>
<td colspan="2" style="padding:0 0 5px 0; font-family:arial; font-size:11px; color:#333333;" >
<asp:TextBox ID="result" runat="server" ReadOnly="True" TextMode="MultiLine" Width="100%" Wrap="False" Height="60px" ></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnCalculate" runat="server" CssClass="mybutton" Text="Calculate" onclick="btnCalculate_Click" /></td>
</tr></table>
</form>
</body>
</html>

Copy this code and save it as calculator.aspx. You can use windows NotePad to create aspx file.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
©  2008,   http://ramui.com   All rights reserved.
Powered by phpBB