VBScript Language Reference
VBScript Language Reference
VBScript is the default scripting language for ASP and Windows Script Host (WSH). This reference covers the essential language features.
Variables and Constants
Option Explicit ' Require variable declarations Dim strName, intAge, blnActive strName = "John" intAge = 30 blnActive = True Const MAX_RETRIES = 3 Const APP_NAME = "Flamenet Portal"
Data Types
VBScript has a single data type: Variant. The variant subtype is determined by the value assigned:
| Subtype | Description | Example |
|---|---|---|
| Empty | Uninitialized variable | Dim x |
| Null | No valid data | x = Null |
| String | Character string | "Hello" |
| Integer | -32,768 to 32,767 | 42 |
| Long | -2B to 2B | 100000 |
| Boolean | True or False | True |
| Date | Date/time value | #6/15/2001# |
| Object | COM object reference | Set obj = ... |
Control Flow
' If...Then...Else
If intAge >= 18 Then
WScript.Echo "Adult"
ElseIf intAge >= 13 Then
WScript.Echo "Teenager"
Else
WScript.Echo "Child"
End If
' Select Case
Select Case strRole
Case "admin"
WScript.Echo "Administrator"
Case "mod"
WScript.Echo "Moderator"
Case Else
WScript.Echo "Member"
End Select
' For...Next
For i = 1 To 10
WScript.Echo i
Next
' For Each
Dim arr
arr = Array("apple", "banana", "cherry")
For Each item In arr
WScript.Echo item
Next
' Do While
Do While Not rs.EOF
WScript.Echo rs("Name")
rs.MoveNext
Loop
String Functions
| Function | Description | Example |
|---|---|---|
| Len(s) | String length | Len("Hello") = 5 |
| Left(s, n) | Left n characters | Left("Hello", 3) = "Hel" |
| Right(s, n) | Right n characters | Right("Hello", 2) = "lo" |
| Mid(s, start, len) | Substring | Mid("Hello", 2, 3) = "ell" |
| InStr(s, find) | Position of substring | InStr("Hello", "ll") = 3 |
| Replace(s, old, new) | Replace text | Replace("abc", "b", "x") = "axc" |
| UCase(s) / LCase(s) | Case conversion | UCase("hello") = "HELLO" |
| Trim(s) | Remove spaces | Trim(" hi ") = "hi" |
| Split(s, d) | Split to array | Split("a,b,c", ",") = Array |
| Join(arr, d) | Join array | Join(arr, ",") = "a,b,c" |