VBScript (Visual Basic Scripting Edition) is a interpreted scripting language from Microsoft. It is a subset of
the Visual Basic programming language and follows the same syntax. Once you've learned VBScript, you'll be well on your way to understanding Visual Basic. Similarly, if you're already a Visual Basic programmer, you'll be productive with VBScript in no time.
Windows and network systems administrator Jerry Lees is your VBScript guide, as he explains some of the basic VBScript statements below. You can find more advanced VBScript content on Jerry's blog, The VBScript Network and Systems Administrator's Cafe.
The DIM statement is used to declare variables. To save space in your code, you can declare more than one variable in a single statement by separating each variable with a comma. The Const statement is useful when you want to reference a specific, unchanging, value in your code multiple times without having to type it in over and over. When you use the Option Explicit statement, you must explicitly declare all of your variables. This helps you to avoid typos.
VBScript Looping Statements
The If...Then...Else statement in VBScript is very similar to the Select Case statement, except it normally only allows for 2 possibilities (true/false) in your condition.
The Do...Loop statement is very useful to execute a block of code more than once. The For...Next statement is for situations where you need to loop through a piece of code a specific number of times. The For Each...Next statement will also loop through a block of code a specific number of times, but is used when the number of loops needed at runtime is unknown.
Other VBScript Statements
The Select...Case statement is a very powerful way to easily perform specific actions based on a comparison of a variable to a series of cases that you specify.
The Exit statement allows you to exit a block of code. It can be used for a subroutine (Exit Sub), function (Exit Function) or the entire script.
The Erase statement is used to erase all the values of an array. The array size and dimensions remain intact.
If you enjoyed this user-generated content, be sure to visit The VBScript Network and Systems Administrator's Cafe for more advanced VBScript topics.
| GOT DEVELOPER QUESTIONS? YOUR PEERS HAVE ANSWERS