Home NT WSH
VB Script Constants and Variables

Creating Constants and Variables

Create constants in VBScript with the Const statement.

   For example: 
   
   Const MY_STRING = "This is my string."
   Const MY_PERCENTAGE = 75
   Const DATE_OF_BIRTH = #6-1-97#
   
   Note that strings are enclosed in quotes (")
   Dates and times are enclosing in number signs (#)

Variables
  
   Create (variant) variables in VBScript with the Dim statement,
   the Public statement, and the Private statement. 
   
   For example: 
   
   Dim StrMyTextString
   
   Dim IntMyInteger

   Dim MyArray(10)
   
   The Option Explicit statement should be the first statement
   in every VB script - to prevent accidental implicit declarations.  

Assigning Values to Variables

   Values are assigned to variables with = as follows: 

   IntMyInteger = 200

   StrMyTextString = "This is an example string"

   MyArray(0) = 23
   MyArray(1) = 45
   MyArray(2) = 500
   ...
   MyArray(10) = 21

"Whether you think you can or think you can't -- you are right" - Henry Ford



Back to the Top

Simon Sheppard
SS64.com