BrainDump
  Home arrow BrainDump arrow Conditional Statements in VBScript
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Conditional Statements in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-01-22

    Table of Contents:
  • Conditional Statements in VBScript
  • The IF statement
  • Select Case
  • Conditional Expressions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Conditional Statements in VBScript
    (Page 1 of 4 )

    Inevitably, as you progress to more complex scripts, your scripts will need to be able to make decisions and take separate actions based upon those conditions. For this, VBScript provides conditional statements.

    Conditional statements route code execution based upon the value of some expression.  These conditions typically involve some comparison and are evaluated to either True or False.  The conditional statement then branches off code execution accordingly.

    Imagine the following scenario:

    You're writing a script to open or close a door.  Which action should be performed is strictly dependent upon the current state of the door.  In other words, you can't open a door that's already open!  So some code might look like this.

    Set objDoor = CreateObject("My.Door")

    If objDoor.IsOpen Then

       objDoor.Close

     

    Else

       objDoor.Open

     

    End If

    In this hypothetical example we have an object name objDoor that represents our door.  This object class has Open and Close methods to perform our action as  well as an IsOpen property that returns a value of True if the door is currently open.

    I've made use of an IF statement to check the value of the IsOpen property.  If it evaluates to True the immediate code block is executed.  If it evaluates to False, the Else block is executed.  Code would then continue with the line immediately following the End If statement.

    Of course, this is an extremely simplified example.  The If statement offers some more advanced flexibility and there are several ways to construct much more intricate expressions.  To begin, let's take a look at the If statement up close.

    More BrainDump Articles
    More By Nilpo


     

    BRAINDUMP ARTICLES

    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway