Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Conditional Statements

VBScript allows you to control how your scripts process data through the use of conditional and looping statements. By using conditional statements you can develop scripts that evaluate data and use criteria to determine what tasks to perform. Looping statements allow you to repetitively execute lines of a script. Each offers benefits to the script developer in the process of creating more complex and functional web pages.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.

if statement :
if statement is used when you want to execute a set of code when a condition is true.

if...then...else statement :
if…then…else statement is used when you want to select one of two sets of lines to execute.

if...then...elseif statement :
if...then...elseif statement is used when you want to select one of many sets of lines to execute.

select case statement :
select case statement is used when you want to select one of many sets of lines to execute

If....Then
If you want to execute only one statement when a condition is true, you can write the code on one line:

if i>0 Then msgbox "Positive Number"

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 statement with the keyword "End If":

if i>0 Then
   msgbox " Positive Number"
   i = i+1
end If

If....Then….Else
If you want to execute a statement if a condition is true and execute another statement if the condition is not true, you must add the "Else" keyword:

if i>0 then
   msgbox "Positive Number"
else
   msgbox "Negative Number"
end If

The first block of code will be executed if the condition is true, and the other block will be executed otherwise.

If....Then.....Elseif
You can use the if...then...elseif statement if you want to select one of many blocks of code to execute

if percentage>=80 then
   msgbox "Your Grade is A."
 elseif percentage>=70 then
   msgbox "Your Grade is B."
 elseif percentage>=60 then
   msgbox "Your Grade is C."
 else
   msgbox "Your Grade is D."
end If

Select Case
The Select Case statement provides an alternative to the If..Then..Else statement, providing additional control and readability when evaluating complex conditions. It is well suited for situations where there are a number of possible conditions for the value being checked. Like the If statement the Select Case structure checks a condition, and based upon that condition being true, executes a series of statements.

Example
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.

 
     
   
VBScript Tutorial
 
  Introduction
Introduction
  How to
How to
  Where to
Where to
  Working With Variables
Working With Variables
  Arrays
Arrays
  VBScript Procedures
VBScript Procedures
  Conditional Statements
Conditional Statements
  For Next Loop
For Next Loop
  While Loop
While Loop
  Comments
Comments
  Date
Date
  MsgBox
MsgBox
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Niche Marketing Research In Plain English Ebook Niche Marketing Research In Plain English
   
Download Everything You Ever Wanted to Know about Article Marketing Ebook Everything You Ever Wanted to Know about Article Marketing
   
Download Enhance Your Financial Intelligence Ebook Enhance Your Financial Intelligence
   
Download tears of the mystic rose Ebook tears of the mystic rose
   
Download Importance of Search Engine Article and Directory Submission Ebook Importance of Search Engine Article and Directory Submission
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz