4:01 pm Saturday, July 31, 2010
     
SERVER TRANSFER COMPLETE. UNDER CONSTRUCTION.
            Search About Contact Home
Creating Your First ASP Page Tutorial
AaronOutpost : ASP / Tutorials / ASP 101 / If, Else, Then Statements

ASP 101: If, Else Then Statements
By: Aaron B. Copyright AaronOutpost.com

 

    This is part 4 of 6 of ASP 101 by AaronOutpost.com. If you are unsure of what we may be talking about in the tutorial, view the previous parts.

So far we have created your first ASP page, we have defined a value, displayed it on the page, as well as discussed some date and time functions. We are now going to take that exact same page and modify it. I am going to show you how to use If, Else, Then statements with the date and time functions you just learned.

Let's begin.

 

Part 4:
IF, ELSE, THEN

If, Else, Then can be used logically to make the server perform certain tasks depending on what you have programmed. The just jump right into an example.

Let's say you want to have a message say good morning or good evening depending on the hour of the day. I'm using the time since this was our last step. So we are going to say If  the time is greater then 12 then say Good Evening Else it must be before noon so say Good Morning. We then close the If statement with End If

<% If Hour(Now()) > 12 Then %>

Good Evening

<% Else %>

Good Morning

<% End If %>

You can also have If statements inside of If Statements. So let's narrow it down to Good Morning, Good Afternoon, and Good evening.

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour > 12 Then
'If hour is under 5 pm then afternoon
If intHour < 17 Then %>
Good Afternoon!
<% Else %>
Good Evening!
<% End If
Else %>
Good Morning!
<% End If %>

If you used <> this means not equal to. So let's say if the hour is not equal to 12 then it's not between 12 and 1 p.m. so for humor's sake let's say that is your lunch time.

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour <> 12 Then %>
It's not noon so it's not lunch time!
Else %>
It's 12 o'clock, lunch time!
<% End If %>

This could also be inversely written and get the same result.

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour = 12 Then %>
It's 12 o'clock, lunch time!
Else %>
It's not noon so it's not lunch time!
<% End If %>

Add which ever codes you wish to your first asp page. I added

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour > 12 Then
'If hour is under 5 pm then afternoon
If intHour < 17 Then %>
Good Afternoon!
<% Else %>
Good Evening!
<% End If
Else %>
Good Morning!
<% End If %>

We will cover more If, Else, Then statement in following parts.

CONGRATULATIONS!!!

Now, you have completed part 3 of 6 Learning ASP 101 by AaronOutpost.com.

Open Viewable Example
Continue to part 5: Security

<html>

<head>

<title>My First ASP Page</title>

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#003300" vlink="#006600" alink="#689577">

 

<%

'Dimension variables

Dim MyVariable 'Comment on what this variable holds

 

'Define a value for the MyVariable
MyVariable = "I am learning ASP! This is my first programmed variable!"
%>

<br><br>
<font face="Arial" size="2" color="#000000">
<%
= MyVariable %><br><br>

Server Date & Time is: <%= Now() %><br><br>

Server Time is: <%= Time() %> <br><br>

Server Date is: <%= Date() %><br><br>

Current Hour is: <%= Hour(Now()) %><br><br>

Current Minute is: <%= Minute(Now()) %><br><br>

Current Second is: <%= Second(Now()) %><br><br>

vbGeneralDate: <%= FormatDateTime(Now(), 0) %><br><br>

vbLongDate: <%= FormatDateTime(Now(), 1) %><br><br>

vbShortDate: <%= FormatDateTime(Now(), 2) %><br><br>

vbLongTime: <%= FormatDateTime(Now(), 3) %><br><br>

vbShortTime: <%= FormatDateTime(Now(), 4) %><br><br>

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour > 12 Then
'If hour is under 5 pm then afternoon
If intHour < 17 Then %>
Good Afternoon!
<% Else %>
Good Evening!
<% End If
Else %>
Good Morning!
<% End If %>


</font>

</body> </html>

 


AaronOutpost : ASP / Tutorials / ASP 101 / If, Else, Then Statements


Random_Image
News & Updates

ASP Inline Calendar 3.9 (January 5, 2008)
Future Home of News & Updates (January 5, 2008)

 

Photo Special

Schedule an appointment

Available in & around:
Centreville VA, Spotsylvania VA,
Summersville WV, & Charleston WV
.

  • NAME YOUR PRICE
    • Email your:
    • Event
    • Hours Needed
    • Photos Needed
    • Disks or Prints
    • and Price You're Willing To Pay
ASP Inline Calendar

$100 Installation Special

PROFESSIONAL INSTALLATION OF YOUR ASP INLINE CALENDAR. REDUCE THE HASSLE, LET US INSTALL YOUR ASP INLINE CALENDAR. SEND A FORMAL REQUEST FOR INSTALLATION WITH SERVER ACCESS INFORMATION. WE WILL NEED FTP ACCESS ALONG WITH CONTROL PANEL ACCESS.

Purchase A Calendar
Information
Demo
Ask A Question

User must provide ftp access to server. Installations are not guaranteed. We work with your service provider to get your calendar installed.

 

Centreville, VA      -      Spotsylvania, VA      -      Charleston, WV      -      Summersville, WV

© Copyright AaronOutpost.com 2010. All rights reserved.