Dim

Explicitly declare a new variable or array variable.

Syntax 
       Dim Varname[([subscript])] [,Varname[([subscript])] ...]

Key
   Varname     Name for the new variable
   subscript   Number of elements in an array variable

Dim statements are not required unless the VBScript contains an Option Explicit statement.

Unlike many other languages there is no need to specify a data type (integer, string, object etc) All VBScript variables are variants. Most experienced scripters will choose variable names that indicate the data type to be stored e.g. strEmployee.

Examples

Option explicit

Dim myString, price
myString="Hello world"
price=123

Create an Array Variable with 3 elements:

Dim strPrintQueues(2)
strPrintQueues(0)="HP Deskjet 1200"
strPrintQueues(1)="Kyocera first floor"
strPrintQueues(2)="Mikes printer"

“Listen to many, speak to a few” ~ William Shakespeare

Related:

Array - Add values to an Array variable
Private VarName - Declare a local variable/array variable
Public VarName - Declare a public variable/array variable
Equivalent Powershell command: $MyVariable = SomeValue


© Copyright SS64.com 1999-2014
Some rights reserved