BrainDump
  Home arrow BrainDump arrow Page 3 - 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 - Select Case


    (Page 3 of 4 )

    VBScript provides another method for making decisions as well.  This is the Select Case statement.  It acts in much the same way as an IF statement but it allows you to make a decision between several alternatives for a single expression.

    Select Case expression

          Case value

                code

          [Case value

                code]

          [Case Else

                code]

    End Select

    The opening statement must contain a conditional expression without any operator.  Each Case has a possible value for that expression.  This works off of an equality comparison.  You may list as many possible cases as you need.  If included, Case Else is executed if no other condition is met.

    Select Case strColor

       Case "blue"

           WScript.Echo "Color is blue"

     

       Case "red"

           WScript.Echo "Color is red"

     

       Case "green"

           WScript.Echo "Color is green"

     

       Case Else

           WScript.Echo "Color is not blue, red, or green"

     

    End Select

    In this example, we're checking the value of the strColor variable.  Code is executed based upon what color strColor is equal to.  Here is the equivalent If statement.

    If strColor = "blue" Then

       WScript.Echo "Color is blue"

     

    ElseIf strColor = "red" Then

       WScript.Echo "Color is red"

     

    ElseIf strColor = "green" Then

       WScript.Echo "Color is green"

     

    Else

       WScript.Echo "Color is not blue, red, or green"

     

    End If

    Select Case allows a much simpler way to make several comparisons to the same expression and makes for easier readability.

    More BrainDump Articles
    More By Nilpo


     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





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