Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>How many days old are you</h1>
<asp:Label ID="Label1" runat="server" Text="Enter Your birthday"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Calculate" />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.vb
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If IsDate(TextBox1.Text) Then
Dim bday As DateTime = DateTime.Parse(TextBox1.Text)
Dim days As Integer
days = ((DateTime.Now - bday).TotalDays) - 1
Label2.Text = days.ToString
Else
Label2.Text = "Enter a valid date"
End If
Catch
Dim ex As New Exception("that is not a date, buddy")
Label2.Text = ex.Message
End Try
End Sub
End Class
No comments:
Post a Comment