|
Category
|
Keywords
|
|
Array handling
|
Array
-Returns a Variant containing an array
Dim
A
' Declare array
A
= Array(50,20,30)
'
Store 3 element
B
= A(2) ' B is now 30.
|
|
Dim
-Declares variables and allocates storage space.
Dim
Names(9) ' Declare
an array with 10 elements.
Dim
Names() '
Declare a dynamic array.
Dim
MyVar, MyNum ' Declare two variables.
|
|
Private
-Declares private variables and allocates storage
space
Private
MyNumber ' Private Variant
variable.
Private
MyArray(9) ' Private array variable.
' Multiple Private declarations of Variant variables.
Private
MyNumber, MyVar, YourNumber
|
|
Public
-Declares public variables and allocates storage space
Public
MyNumber ' Public Variant
variable.
Public
MyArray(9) ' Public array variable.
' Multiple Public declarations of Variant variables.
Public
MyNumber, MyVar, YourNumber
|
|
ReDim
-Declares dynamic-array variables, and allocates or
reallocates storage space at procedure level.
Dim
X(1)
' Declare Array variable for 2 elements.
ReDim X(10)
' Redimension for 11 elements.
ReDim
Preserve X(15) ' Redim for 16 with preserve old value
|
|
IsArray
-Returns a Boolean value indicating whether a variable
is an array
Dim
MyVariable
Dim
MyArray(3)
MyArray(0)
= "Sunday"
MyArray(1)
= "Monday"
MyArray(2)
= "Tuesday"
MyVariable
= IsArray(MyArray) ' MyVariable contains
"True".
|
|
Erase
-Reinitializes the elements of fixed-size arrays and
deallocates dynamic-array storage space
Dim
NumArray(9)
Dim
DynamicArray()
ReDim
DynamicArray(9) ' Allocate storage space.
Erase
NumArray ' Each element is reinitialized.
Erase
DynamicArray ' Free memory used by array.
|
|
LBound
-Returns the smallest available subscript for the
indicated dimension of an array.
The lower bound for any dimension is always 0.
|
|
UBound
-Returns the largest available subscript for the
indicated dimension of an array.
Dim
B(200,3,4)
|
Statement
|
Return
Value
|
|
UBound(B,
1)
|
200
|
|
UBound(B,
2)
|
3
|
|
UBound(B,
3)
|
4
|
|
|
Assignments
|
Set
-Assigns an object reference to a variable or
property, or associates a procedure reference with an
event.
Set
fso = CreateObject("Scripting.FileSystemObject")
Set
d = fso.GetDrive(fso.GetDriveName(drvPath))
|
|
Comments
|
Comments
using ' or Rem
-Includes explanatory remarks in a program.
Dim
MyStr1, MyStr2
MyStr1
= "Hello" : Rem Comment after a statement
separated by a colon.
MyStr2
= "Goodbye" ' This is also a comment; no
colon is needed.
Rem
Comment on a line with no code; no colon is needed.
|
|
Constants/Literals
|
Empty
-The Empty keyword is used to indicate an
uninitialized variable value. This is not the same
thing as Null
|
|
Nothing
-The Nothing keyword in VBScript is used to
disassociate an object variable from any actual object
|
|
Null
-The Null keyword is used to indicate that a variable
contains no valid data. This is not the same thing as
Empty
|
|
True
-The True keyword has a value equal to -1.
|
|
False
-The False keyword has a value equal to 0.
|
|
Control flow
|
Do...Loop
-Repeats a block of statements while a condition is
True or until a condition becomes True.
Dim
Counter
Counter = 0
' Initialize variables.
Do While Counter < 30
' loop Condition.
Counter = Counter + 1 ' Increment Counter.
If Counter = 15 Then ' If condition
is True...
Exit Do
' Exit loop.
End If
Loop
|
|
For...Next
-Repeats a group of statements a specified number of
times.
For
I = 1 To 10
For J = 1 To 10
For K = 1 To 10
. . .
Next
Next
Next
|
|
For
Each...Next
-Repeats a group of statements for each element in an
array or collection.
Dim fso, f, f1, fc, s
Set fso =
CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
|
|
If...Then...Else
-Conditionally executes a group of statements,
depending on the value of an expression.
If
A > 10 Then
B = A + 5
else
B = A + 10
End If
|
|
Select
Case
-Executes one of several groups of statements,
depending on the value of an expression.
Dim
Color, MyVar
Sub
ChangeBackground (Color)
MyVar = lcase (Color)
Select Case MyVar
Case "red"
document.bgColor = "red"
Case "green" document.bgColor =
"green"
Case "blue"
document.bgColor = "blue"
Case Else MsgBox
"pick another color"
End Select
End
Sub
|
|
While...Wend
-Executes a series of statements as long as a given
condition is True.
Dim
Counter
Counter
= 0 ' Initialize variable.
While
Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
Alert Counter
Wend
' End While loop when Counter > 19.
|
|
With
-Executes a series of statements on a single object.
With
MyLabel
.Height = 2000
.Width = 2000
.Caption = "This is MyLabel"
End
With
|