BrainDump
  Home arrow BrainDump arrow Page 4 - 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

    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!

    Understanding Variables in VBScript - Data types
    (Page 4 of 4 )

    As I mentioned previously, there are multiple data types in VBScript.  They can be divided into two major categories: numeric and non-numeric.  As their name implies, numeric variables are variables whose value is recognized as a number.  Non-numeric types are the opposite and include strings, Booleans, and empty variables among others.

    You can determine a variable’s data subtype by using VBScript’s VarType or TypeName function.  The table below lists the return values for the VarType function and also serves as a list of the available data subtypes in VBScript.

    Constant

    Value

    Description

    vbEmpty

    0

    Empty (uninitialized)

    vbNull

    1

    Null (no valid data)

    vbInteger

    2

    Integer

    vbLong

    3

    Long integer

    vbSingle

    4

    Single-precision floating-point number

    vbDouble

    5

    Double-precision floating-point number

    vbCurrency

    6

    Currency

    vbDate

    7

    Date

    vbString

    8

    String

    vbObject

    9

    Automation object

    vbError

    10

    Error

    vbBoolean

    11

    Boolean

    vbVariant

    12

    Variant (used only with arrays of Variants)

    vbDataObject

    13

    A data-access object

    vbByte

    17

    Byte

    vbArray

    8192

    Array

    The TypeName function works similarly, but instead it returns the variable type as a string.  You can see an example of both in the example below.

    Dim MyCheck

    MyCheck = VarType(300)          ' Returns 2.

    MyCheck = VarType(#10/19/62#)   ' Returns 7.

    MyCheck = VarType("VBScript")   ' Returns 8.

     

    Dim ArrayVar(4), MyType

    NullVar = Null   ' Assign Null value.

     

    MyType = TypeName("VBScript")   ' Returns "String".

    MyType = TypeName(4)            ' Returns "Integer".

    MyType = TypeName(37.50)        ' Returns "Double".

    MyType = TypeName(NullVar)      ' Returns "Null".

    MyType = TypeName(ArrayVar)     ' Returns "Variant()".

    VBScript provides a number of other functions that can be used to determine the type and state of your variables.  These functions return Boolean values according to the table below.

    IsArray

    Returns True if a variable references an array.

    IsDate

    Returns True if a value is a date or can be converted to a date.

    IsEmpty

    Returns True if a variable is uninitialized.

    IsNull

    Returns True if a variable is initialized but does not contain valid data.

    IsNumeric

    Returns True if a variable’s value can be interpreted as a number.

    IsObject

    Returns True if a variable represents an object.

    This article is designed to be an introduction to using variables in VBScript.  At this point, you should be able to create and implement variables in VBScript, and also be aware of their types and states.  In future articles, I will demonstrate how to work with specific data types as well as how to convert between them.

    Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 1 hosted by Hostway