Você está na página 1de 5

VBScript Conditional Statements

HOME VBScript Conditional Statements


VBScript Tutorial ASP Ecommerce & Shopping
VB HOME Cart
VB Introduction WEB HOSTING
VB How to $15 Domain Name
VB Where to Registration
Examples
VB Variables Save $20 / year!
VB Procedures
The if...then...else statement UK Domain Names
VB Conditional
This example demonstrates how to write the if...then..else statement. Web Hosting
VB Looping
Merkaweb Dominios
Examples The if...then...elseif... statement Buy UK Domain Names
VB Examples This example demonstrates how to write the if...then...elseif statement. Register Domain Names
References Website Hosting
VB Functions The select case statement Domain Hosting
VB Keywords This example demonstrates how to write the select case statement. Web Hosting
Cheap Domain Names UK
Domain Names UK
Quality Web Hosting
Conditional Statements
Webmail & POP3 Email

Very often when you write code, you want to perform different actions Web Hosting UK
for different decisions. You can use conditional statements in your code Dedicated Servers UK
to do this. Domain Names UK
Business Web Hosting
In VBScript we have three conditional statements: Free Web Hosting
Cheap Web Hosting
if...then...else statement - use this statement if you want to Web Hosting Reseller
select one of two sets of lines to execute
Website Design UK
if...then...elseif statement - use this statement if you want to
select one of many sets of lines to execute Reseller Hosting
select case statement - use this statement if you want to
select one of many sets of lines to execute HTML & Flash
Download HTML Editor
Flash Web Builder
Flash Templates

If....Then.....Else HOTELS
Amsterdam Hotels
Boston Hotels
You should use the If...Then...Else statement if you want to Chicago Hotels
London Hotels
execute some code if a condition is true Los Angeles Hotels
select one of two blocks of code to execute Miami Hotels
New York Hotels
If you want to execute only one statement when a condition is true, New Orleans Hotels
you can write the code on one line: Paris Hotels
Rome Hotels
if i=10 Then msgbox "Hello" Hotel Reservations
Discount Hotels
Hotel Rooms
There is no ..else.. in this syntax. You just tell the code to perform one
action if the condition is true (in this case if i=10). Web Building

http://www.w3schools.com/vbscript/vbscript_conditionals.asp (1 of 5)4/15/2004 12:26:07 AM


VBScript Conditional Statements

Website Templates
If you want to execute more than one statement when a condition is
true, you must put each statement on separate lines and end the Website Builder
statement with the keyword "End If": Flash Templates
Web Templates

if i=10 Then Shopping


msgbox "Hello" Discount Apparel
i = i+1 Online Coupons
end If Cooking tools
Men & women clothing
Office supply
There is no ..else.. in this syntax either. You just tell the code to
perform multiple actions if the condition is true. Home Finance
Shopping UK

If you want to execute a statement if a condition is true and execute UK Wholesalers


another statement if the condition is not true, you must add the "Else"
Mobile Phones
keyword:
Direct TV
Plasma TV
if i=10 then Prepaid Phones
msgbox "Hello" 123 Fast Loans
else
msgbox "Goodbye" Software
end If Meta Search Engine
Your Own Web Site?

The first block of code will be executed if the condition is true, and the Read W3Schools
other block will be executed otherwise (if i is not equal to 10).
Hosting Tutorial

If....Then.....Elseif WebDev Books


Grow Your
You can use the if...then...elseif statement if you want to select one of Web Design
many blocks of code to execute: Business!

if payment="Cash" then Download
msgbox "You are going to pay cash!"
a Sample
elseif payment="Visa" then
msgbox "You are going to pay with visa."
elseif payment="AmEx" then Learn CSS
msgbox "You are going to pay with American Express." Positioning the
else easy way!
msgbox "Unknown method of payment." Download
end If
a Sample

Learn PHP &


MySQL the easy
Select Case
way!
Download
You can also use the SELECT statement if you want to select one of
many blocks of code to execute: a Sample

SELECTED LINKS
University Online
Master Degree
Bachelor Degree

Web Security
Web Statistics
Web Standards

Web Quality

http://www.w3schools.com/vbscript/vbscript_conditionals.asp (2 of 5)4/15/2004 12:26:07 AM


VBScript Conditional Statements

select case payment


case "Cash"
msgbox "You are going to pay cash"
case "Visa"
msgbox "You are going to pay with visa"
case "AmEx"
msgbox "You are going to pay with American Express"
case Else
msgbox "Unknown method of payment"
end select

This is how it works: First we have a single expression (most often a


variable), that is evaluated once. The value of the expression is then
compared with the values for each Case in the structure. If there is a
match, the block of code associated with that Case is executed.

Product Spotlight

Infragistics NetAdvantage 2004 Vol. 1


Download the latest trial version of the ultimate presentation layer
toolset for building stunning user interfaces for Windows Forms, ASP.
NET, Tablet PC and COM applications.

Want To Be A Web Master?

If you want to be a Web Master, you will have to host your web site
with an ISP (Internet Service Provider).

Redstation, founded in 1998, provides fast, reliable, feature-packed


web hosting accounts; from a single web hosting package costing just
59 per year to a high-performance Dell dedicated server.

Web hosting accounts include access to the Redstation Control Panel


allowing real-time administration of every aspect of your website and
email configuration - 24 hours a day, 7 days a week.

Redstation operates one of the fastest internet connections in the UK


with more than 200Mbits of available bandwidth. Combined with
multiple enterprise class firewalls your website is in safe hands with
Redstation.

Visit Redstation

http://www.w3schools.com/vbscript/vbscript_conditionals.asp (3 of 5)4/15/2004 12:26:07 AM


VBScript Conditional Statements

Get Your Diploma!

W3Schools' Online Certification Program is


the perfect solution for busy professionals
who need to balance work, family, and
career building.

The HTML Certificate is for developers who


want to document their knowledge of HTML
4.01, XHTML, and CSS.

The ASP Certificate is for developers who


want to document their knowledge of ASP,
SQL, and ADO.

HTML Utopia: Designing Without Tables Using CSS

Write faster loading, dramatically


smaller pages
Speed up site maintenance by
separating the content from the
layout
Write Device-independent pages
that will work on everything from a
PC to an Internet-enabled
refrigerator
Write search-engine friendly pages
that can actually be understood by
search-engine spiders
Write accessible code, which is
now a legal requirement in some
countries

Dan Shafer's book is the definitive guide to learning and applying the
principles of CSS to your Website.

We Help You For Free. You Can Help Us!

Make a small donation


Tell your newsgroup or mailing list
Link to us from your pages
Help us correct errors and broken links
Help us with spelling and grammar
Validate the XHTML code of this page

Jump to: Top of Page or HOME or Printer friendly page

Search W3Schools:

http://www.w3schools.com/vbscript/vbscript_conditionals.asp (4 of 5)4/15/2004 12:26:07 AM


VBScript Conditional Statements

Go!

What Others Say About Us

Does the world know about us? Check out these places:

Google Yahoo Alta Vista MSN Lycos Excite Ask Jeeves HotBot

W3Schools is for training only. We do not warrant the correctness of the


content. The risk of using it remains entirely with the user. While using
this site, you agree to have read and accepted our terms of use and
privacy policy.

Copyright 1999-2004 by Refsnes Data. All Rights Reserved.

How W3Schools was converted to


XHTML

http://www.w3schools.com/vbscript/vbscript_conditionals.asp (5 of 5)4/15/2004 12:26:07 AM

Você também pode gostar