BrainDump
  Home arrow BrainDump arrow Page 3 - Understanding Variables 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

Understanding Variables in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-03-18

    Table of Contents:
  • Understanding Variables in VBScript
  • Variable Names and Scope
  • Initializing and Debugging Variables
  • Data types

  • 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

    Ajax Application Generator Generate database 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!

    Understanding Variables in VBScript - Initializing and Debugging Variables
    (Page 3 of 4 )

    Now that you’ve seen what variables are and how to name them, it’s time to begin putting them to use in your own scripts.  To do that, you first need to learn how to declare, or create them.

    There are two terms that you will hear used when talking about variables.  You should become familiar with their proper definitions.  Declaring a variable means creating its reference in memory.  This makes it available for use.  Initializing a variable means assigning its first value.  In VBScript, variables are often declared and initialized at the same time.

    The proper method for declaring a variable in VBScript is to use the Dim statement.  The Dim statement allocates memory for the variable.

    Dim intNumber

    You declare any number of variables in a single statement by separating them with commas.

    Dim strName, strAddress, strCity, strState, intZipCode

    In VBScript, you do not need to declare the type associated with the variable as you would in VisualBasic.

    Dim intNumber As Integer

    The use of the As statement in VBScript will result in an "Expected end of statement" error, since the As keyword is not recognized.

    Explicit declarations allow you to control the scope of your variables more effectively.

    VBScript will automatically create any variable found in an expression.  There may be times when you don’t want this to happen.  Imagine that you are trying to debug a script where you mistyped a variable name.  Your script will most likely not perform as you intended it to, but in most cases, it won’t throw any errors either.  Forcing VBScript to only use explicitly declared variables can help you avoid this scenario.

    Option Explicit:

    Using the Option Explicit statement at the beginning of your script will force the VBScript interpreter to throw an error any time it encounters a variable that was not explicitly declared.  In other words, it forces the use of the Dim statement.

    More BrainDump Articles
    More By Nilpo


       · If you plan to master any programming language, it's a good practice to develop a...
     

    BRAINDUMP ARTICLES

    - 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
    - VBScript: More Fun with the Date Functions
    - Vista Price Cuts Dissected




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