VBScript Tutorial

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.

VBScript Variables

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.

Your fellow developers have faced the same or similar problems.
So ask your own question on the IT Knowledge Exchange community.

This was first published in July 2008

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.