BrainDump
  Home arrow BrainDump arrow Conditional Statements in VBScript
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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
     
     
    ADVERTISEMENT


    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

    - Firefox on Windows Mobile
    - Microsoft`s Sneaky Firefox Add-On Installati...
    - Microsoft`s Answer to Google Search - Bing
    - Doing Statistical Analysis with MS Excel
    - Extracting Google-Indexed Web Site Pages Usi...
    - Advanced String Manipulation Using MS Excel
    - Using Goal Seek and Solver in MS Excel
    - Internet Explorer 8: A Hands-on View
    - Tools for Beginning Game Developers
    - XAMPP: Tips for Running an Apache/MySQL Serv...
    - Improving Your Visual Studio Workspace
    - A Look at Microsoft`s Mobile Operating System
    - Microsoft Internet Explorer 8: Mixed Reactio...
    - Configuring WSUS 3.0 on Windows Server 2008
    - Migrating to Windows Server 2008





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT