IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Basics   Print This    All Groups  
  From the February 2016 Issue of Prestwood eMag
 
ASP Classic Language Basics:
ASP Classic If Statement (If..ElseIf..Else..End If)
 
Posted 14 years ago on 12/8/2008 and updated 3/20/2009
ASP Classic Code Snippet:
 A flashcard from our ASP Classic Flashcards Library
 A code snippet from our ASP Classic Code Snippets Page

KB101383

ASP Classic If Statement

The End If is optional if you put your code on a single line.

Syntax Example:
//Single line example.
If X = True Then Response.Write "hello" 
  
//Complete example.
If X = True Then
  '>>>do something.
ElseIf Y = "ABC" Then
  '>>>do something.
Else
  '>>>do something.
End If

Full HTML Page Example

Here's a real example you can save as an ASP page and try out.

<%@LANGUAGE='VbScript'%>
<%
Option Explicit
%>
<html>
<body>
<%
Dim StatementVar

StatementVar=1

If StatementVar=1 Then
Response.Write "War doesn't determine who's right - only who's left."
ElseIf StatementVar=2 Then
Response.Write "Lost time is never found again."
Else
Response.Write "History will be kind to me for I intend to write it."
End If
%>
</body>
</html>

You will have to change the value of StatementVar to see the other quotes.

Optional End If

With ASP you don't always have to include the ending End If. This makes for some clean looking code in certain situations. For example when you have a series of conditional code lines that each resule in a single line of code.

Here's a simple demo:

If true then Response.Write "hi "
If true then Response.Write "Mike "
If true then Response.Write "Prestwood."

More Info


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

The method of the serene champion is a pleasant book. The essayist has been composing for quite a while. Positive things like bestessay uk ought to be valued. Difficult work ought to be paid in a proper way so new things and thoughts can win.

Posted 23 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1295A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101383 Counter
35302
Since 12/8/2008
Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2022 Prestwood IT Solutions.   [Security & Privacy]