A VBScript (Visual Basic Script) egy Visual Basic-szerű nyelv, amit sok alkalmazás (pl. Microsoft Outlook, Internet Explorer—IE) és fejlesztő keretrendszer-rendszer (pl. Microsoft Visual Studio) használ. Ezen kívül az ASP alapnyelve is a VBScript. Habár a Microsoft eredetileg a weben használható script nyelvnek tervezte, a VBScript népszerű nyelv lett a Windows-alapú batch fájlok írására a Windows Scripting Host (WSH) használatával. A WHS segítségével a Windows op. rendszer a VBScript fájlokat futtatható állományokként kezeli. Ezáltal a VBScript gazdag funkcionalitását rendszer-szintű szkriptek írására is lehet használni. Hátránya a nyelvnek, hogy a böngészők közül csak az IE képes futtatni a VBScript-et.
A WSH egy rendszer modul, ami a VBScript fájlokat a Windows rendszeren futtatható állománnyá alakítja. A WSH rendelkezésre áll a különböző Windows operációs rendszereken. A Windows 2000-ben (Win2K) a WSH standard operációs rendszer komponens. A Windows 98-ban a WSH választható komponens, amit a rendszer beállításakor lehet kiválasztani. A Windows NT 4.0 és Win95 számára kiegészítő komponensként érhető el. A WSH egy Windows-alapú és egy konzol-alapú futtató motorból, a WSH objektum modellből és a VBScript, valamint JScript futtató-motorokból áll. A WSH objektum modell COM objektumok gyűjteménye, így ezek segítségével minden rendszer-funkciót elérhetünk. A technológia, mi lehetővé teszi a WHS számára a VBScript fájlok futtatását, az ActiveX Scripting. Az ActiveX Scripting egy COM-alapú specifikáció, ami lehetővé teszi a Microsoft és más szolgáltatóknak mindenfajta szkriptnyelv futtatását.
A VBScript a VBA (Visual Basic for Applications) legtöbb funlcionalitását örökölte, így a matematikai műveletek, tömbök, adatkonverziók, COM objektumok, eljárások, valamint a dátum, az idő és string-manipulálás támogatását. Mivel a nyelv tervezésénél elsődlegesen Web-fejlesztés igényeit vették figyelembe, ezért eltávolították a direkt I/O műveleteket és lecsupaszították a típusok támogatását annak az érdekében, hogy növeljék a feldolgozás sebességét. Ennek eredményeként a VBScript nem támogatja az explicit típusokat és nem tartalmaz natív parancsokat a kliens-gép lemezének az eléréséhez. A WSH környezetben futtatva viszont ezeket a funkcionalitásokat ki lehet váltani két COM objektum használatával: a FileSystemObject a fájlok és könyvtárak használatához és a WScript, amit a registry írására és olvasására lehet használni. A VBScript legújabb változatához a Microsoft hozzáadott néhány függvényt és bevezették az osztályokat és reguláris kifejezéseket. Ezekkel a kiegészítésekkel a VBScript egyre közelebb kerül egy hatékony programozási nyelv szintjéhez.
Keyword/Feature | Description |
Array handling | |
IsArray | Returns True if a variable is an array |
Erase | Reinitilizes a fixed-size array |
LBound | Returns the lower bound of an array |
UBound | Returns the upper bound of an array |
Assignments | |
= | Assigns a value to a variable |
Let | Assigns a value to a variable |
Set | Assigns an object to a variable |
Comments | |
` | Includes inline comments in your script |
Rem | Includes comments in your script |
Constants/Literals | |
Empty | Indicates an uninitialized variable |
Nothing | Disassociates a variable with an object |
Null | Indicates a variable with no data |
True | Boolean True |
False | Boolean False |
Control flow | |
Do...Loop | Repeats a block of statements |
For...Next | Repeats a block of statements |
For Each...Next | Repeats a block of statements |
If...Then...Else | Conditionally executes statements |
Select Case | Conditionally executes statements |
While...Wend | Repeats a block of statements |
Conversions | |
Abs | Returns absolute value of a number |
Asc | Returns the ASCII code of a character |
AscB | Returns the ASCII code of a character |
AscW | Returns the ASCII code of a character |
Chr | Returns a character from an ASCII code |
ChrB | Returns a character from an ASCII code |
ChrW | Returns a character from an ASCII code |
CBool | Converts a variant to a boolean |
CByte | Converts a variant to a byte |
CDate | Converts a variant to a date |
CDbl | Converts a variant to a double |
Cint | Converts a variant to an integer |
CLng | Converts a variant to a long |
CSng | Converts a variant to a single |
CStr | Converts a variant to a string |
DateSerial | Converts a variant to a date |
DateValue | Converts a variant to a date |
Hex | Converts a variant to a hex string |
Oct | Converts a variant to an octal string |
Fix | Converts a variant to a fixed string |
Int | Converts a variant to an integer string |
Sgn | Converts a variant to a single string |
TimeSerial | Converts a variant to a time |
TimeValue | Converts a variant to a time |
Dates/Times | |
Date | Returns the current date |
Time | Returns the current time |
DateSerial | Returns a date from its parts |
DateValue | Returns a date from its value |
Day | Returns day from a date |
Month | Returns month from a date |
Weekday | Returns weekday from a date |
Year | Returns year from a date |
Hour | Returns hour from a time |
Minute | Returns minute from a time |
Second | Returns seconds from a time |
Now | Returns current date and time |
TimeSerial | Returns a time from its parts |
TimeValue | Returns a time from its value |
Declarations | |
Dim | Declares a variable |
Private | Declares script-level private variable |
Public | Declares public-level public variable |
ReDim | Reallocates an array |
Function | Declares a function |
Sub | Declares a subprocedure |
Error Handling | |
On Error | Enables error handling |
Err | Contains information about last error |
Input/Output | |
InputBox | Prompts the user for input |
MsgBox | Displays a message to the user |
Math | |
Atn | Returns the Arctangent of a number |
Cos | Returns the cosine of a number |
Sin | Returns the sine of a number |
Tan | Returns the tangent of a number |
Exp | Returns the exponent of a number |
Log | Returns the logarithm of a number |
Sqr | Returns the square root of a number |
Randomize | Reseeds the randomizer |
Rnd | Returns a random number |
Operators | |
+ | Addition |
- | Subtraction |
^ | Exponentiation |
Mod | Modulus arithmetic |
* | Multiplication |
/ | Division |
\ | Integer Division |
- | Negation |
& | String concatenation |
= | Equality |
<> | Inequality |
< | Less Than |
<= | Less Than or Equal To |
> | Greater Than |
>= | Greater Than or Equal To |
Is | Compares expressions |
And | Compares expressions |
Or | Compares expressions |
Xor | Compares expressions |
Eqv | Compares expressions |
Imp | Compares expressions |
Objects | |
CreateObject | Creates reference to an OLE object |
IsObject | Returns True if object is valid |
Options | |
Option Explicit | Forces explicit variable declaration |
Procedures | |
Call | Invokes a subprocedure |
Function | Declares a function |
Sub | Declares a subprocedure |
Strings | |
Instr | Returns index of a string in another |
InStrB | Returns index of a string in another |
Len | Returns the length of a string |
LenB | Returns the length of a string |
Lcase | Converts a string to lowercase |
Ucase | Converts a string to uppercase |
Left | Returns the left portion of a string |
LeftB | Returns the left portion of a string |
Mid | Returns the mid portion of a string |
MidB | Returns the mid portion of a string |
Right | Returns the right portion of a string |
RightB | Returns the right portion of a string |
Space | Pads a string with spaces |
StrComp | Compares two strings |
String | Pads a string with a character |
Ltrim | Removes leading spaces from a string |
Rtrim | Removes trailing spaces from a string |
Trim | Removes leading and trailing spaces |
Variants | |
IsArray | Returns True if variable is an array |
IsDate | Returns True if variable is a date |
IsEmpty | Returns True if variable is empty |
IsNull | Returns True if variable is null. |
IsNumeric | Returns True if variable is a number |
IsObject | Returns True if variable is an object |
VarType | Indicates a variable's type |
Habár a VB és a VBScript közötti legnagyobb különbséget talán a VB-hez tartozó fejlesztőrendszer (illetve a VBScript esetében ennek a hiánya) jelenti, több funkció és a hozzájuk tartozó kulcsszavak kimaradtak a VBScript-ből.
Keyword/Feature | Description |
Array Handling | |
Option Base | Declares default lower bound |
Arrays with lower bound <> 0 | All arrays must have 0 lower bound |
Clipboard | |
Clipboard object | Provides access to the clipboard |
Clear | Clears the contents of the clipboard |
GetFormat | Determines format of clipboard object |
GetData | Returns data from the clipboard |
SetData | Stores data in the clipboard |
GetText | Returns text from the clipboard |
SetText | Stores text in the clipboard |
Collection | |
Add | Adds an item to a collection |
Count | Returns number of items in collection |
Item | Returns an item from a collection |
Remove | Removes an item from a collection |
Access collections using ! character | Accesses a collection with ! |
Conditional Compilation | |
#Const | Defines a compiler constant |
#If...Then...#Else | Conditional compilation |
Constants/Literals | |
Const | Defines a constant |
All intrinsic | Predefined constants such as vbOK constants |
Exponent-based | Real numbers using exponents real number |
Trailing data type characters | Defines data types implicitly |
Control Flow | |
DoEvents | Yields execution to Windows |
GoSub...Return | Branches to a label in a procedure |
GoTo | Goes to a label in a procedure |
On Error GoTo | Goes to a label on an error |
On...GoSub | Branches to a label on an index |
On...GoTo | Goes to a label on an index |
Line numbers | Line numbers |
Line labels | Labels define GoTo/GoSub targets |
With...End With | Provides easy access to an object |
Conversion | |
Chr$ | Returns a character from an ASCII code |
Hex$ | Returns string hex from a number |
Oct$ | Returns string octal from a number |
Ccur | Converts expression to currency |
Cvar | Converts expression to a variant |
CVDate | Converts an expression to a date |
Format | Formats a string |
Format$ | Formats a string |
Str | Returns a string form of a number |
Str$ | Returns a string form of a number |
Val | Returns a number from a string |
Data Types | |
All intrinsic data types except variant | Data types such as Date |
Type...End Type | Defines user-defined data type |
Date/Time | |
Date statement | Returns the current date |
Time statement | Returns the current time |
Date$ | Returns the current date |
Time$ | Returns the current time |
Timer | Returns seconds elapsed since midnight |
DDE | |
LinkExecute | Sends command during DDE conversation |
LinkPoke | Sends data during a DDE conversation |
LinkRequest | Receives data during DDE conversation |
LinkSend | Sends data during a DDE conversation |
Debugging | |
Debug.Print | Prints to the debugging window |
End | Shuts down the application |
Stop | Stops the application |
Declaration | |
Declare | Declares a DLL |
Property Get | Defines a user-defined class |
Property Let | Defines a user-defined class |
Property Set | Defines a user-defined class |
Public | Declares a public variable |
Private | Declares a private variable |
ParamArray | Accepts a variable number of arguments |
Optional | Specifies an optional argument |
New | Creates a new object |
Error Handling | |
Erl | Returns the line number of an error |
Error | Returns an error message |
Error$ | Returns an error message |
On Error...Resume | Enables error handling |
Resume | Resumes after an error |
Resume Next | Resumes after an error |
File Input/Output | |
All | Opens, reads, writes, and closes files |
Financial | |
All financial | Financial function such as Rate functions. |
Graphics | |
Cls | Clears the screen |
Circle | Draws a circle |
Line | Draws a line |
Point | Draws a point |
Pset | Changes a point's color |
Scale | Defines the coordinate system |
Prints to a file | |
Spc | Position output using Print |
Tab | Inserts a tab character |
TextHeight | Returns height of a text string |
TextWidth | Returns width of a text string |
LoadPicture | Loads a picture from disk |
SavePicture | Saves a picture to disk |
QBColor | Returns an RGB color code |
RGB | Combines RGB color codes |
Manipulating Objects | |
Arrange | Arranges windows |
Zorder | Changes z-order of windows |
SetFocus | Sets focus to a window |
InputBox$ | Prompts the user for a string |
Drag | Begins a drag-and-drop operation |
Hide | Hides a form |
Show | Shows a form |
Load | Loads a form |
Unload | Unloads a form |
Move | Moves a form |
PrintForm | Prints a form |
Refresh | Repaints a form |
AddItem | Adds item to list box |
RemoveItem | Removes item from a list box |
Miscellaneous | |
Environ | Returns the user's environment |
Environ$ | Returns the user's environment |
SendKeys | Sends keystrokes to a window |
Command | Returns the command line parameters |
Command$ | Returns the command line parameters |
AppActivate | Activates an application's window |
Shell | Launches another program |
Beep | Beeps the speaker |
Object Manipulation | |
GetObject | Returns an OLE object from a file |
TypeOf | Returns the type of an object |
Operators | |
Like | Compares to strings |
Options | |
def type | Sets default data type for variables |
Option Base | Sets default lower bound for arrays |
Option Compare | Defines default comparison method |
Option Private | Defines default scope module |
Printing | |
TextHeight | Returns height of a text string |
TextWidth | Returns width of a text string |
EndDoc | Terminates a print operation |
NewPage | Ejects the current page |
PrintForm | Prints a form |
Strings | |
All fixed-length | Strings with a fixed length |
LCase$ | Converts a string to lowercase |
UCase$ | Converts a string to uppercase |
Lset | Left-aligns a string |
Rset | Right-aligns a string |
Space$ | Pads a string with spaces |
String$ | Pads a string with a character |
Format | Formats a string |
Format$ | Formats a string |
Left$ | Returns left portion of a string |
Mid$ | Returns middle portion of a string |
Right$ | Returns right portion of a string |
Mid Statement | Replaces a portion of a string |
Trim$ | Removes leading and trailing spaces |
LTrim$ | Removes leading spaces from a string |
RTrim$ | Removes trailing spaces from a string |
StrConv | Performs various conversions |
Using Classes | |
TypeName | Defines a user-defined class |
Optional Arguments | |
IsMissing | Indicates missing optional argument |