BMI计算器Visual Studio

时间:2018-02-26 20:08:20

标签: visual-studio

无论出于何种原因,无论何时运行此代码,网页都会显示,但“计算”按钮不会显示BMI和说明。有任何想法吗?这让我发疯了。我认为实际的BMI.aspx.vb代码可能没有正确格式化,但我已经尝试了我能想到的一切。



Public Class BMI
Inherits System.Web.UI.Page
Protected Sub ButtonCalculate_Click(sender As Object, e As EventArgs) Handles ButtonCalculate.Click
Dim Weight As Double = TextWeight.Text
Dim Height As Double = TextHeight.Text
Dim Result As Double = (Weight * 703) / (Height * Height)
LabelBMI.Text = Result

If Result < 18.5 Then
LabelResults.Text = "Underweight"
ElseIf Result >= 18.5 Or Result < 24.9 Then
LabelResults.Text = "Normal weight"
ElseIf Result >= 25 Or Result < 29.9 Then
LabelResults.Text = "Overweight"
ElseIf Result >= 30 Then
LabelResults.Text = "Obese"
End If
End Sub
Protected Sub ButtonClear_Click(sender As Object, e As EventArgs) Handles ButtonClear.Click
TextName.Text = ""
TextAge.Text = ""
TextEmail.Text = ""
TextWeight.Text = ""
TextHeight.Text = ""
LabelResults.Text = ""

TextName.Focus()
End Sub

End Class
&#13;
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/KSU Health and Healing.Master" CodeBehind="BMI.aspx.vb" Inherits="KSUBMI.BMI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h2>BMI Calculator</h2>
<p>
Please fill out this web form!</p>
<p>
First Name:
<asp:TextBox ID="TextName" runat="server"></asp:TextBox>
</p>
<p>
Your Age:
<asp:TextBox ID="TextAge" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeAge" runat="server" ControlToValidate="TextAge" ErrorMessage="RangeValidator" ForeColor="Red" MaximumValue="100" MinimumValue="1">Must be between 1 and 100</asp:RangeValidator>
</p>
<p>
Email Address:
<asp:TextBox ID="TextEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredEmail" runat="server" ControlToValidate="TextEmail" EnableTheming="True" ErrorMessage="Must be entered!" ForeColor="Red"></asp:RequiredFieldValidator>
</p>
<p>
Your Weight (in lbs):
<asp:TextBox ID="TextWeight" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredWeight" runat="server" ControlToValidate="TextWeight" ErrorMessage="RequiredFieldValidator" ForeColor="Red">Cannot be empty or zero</asp:RequiredFieldValidator>
</p>
<p>
Your Height (in inches):
<asp:TextBox ID="TextHeight" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredHeight" runat="server" ForeColor="Red" ControlToValidate="TextHeight">Cannot be empty or zero</asp:RequiredFieldValidator>
</p>
<p>
<asp:Button ID="ButtonCalculate" runat="server" BackColor="Gold" BorderColor="Gold" Text="Calculate BMI" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="ButtonClear" runat="server" BackColor="Black" BorderColor="Black" ForeColor="White" Text="Clear" />
&nbsp;</p>
<p>
Here are your results:
<asp:Label ID="LabelBMI" runat="server"></asp:Label>
<asp:Label ID="LabelResults" runat="server"></asp:Label>
</p>
</asp:Content>
&#13;
&#13;
&#13;

0 个答案:

没有答案