0. VbScript | Basics

All the basic rules you should know about VbScript in the beginning. I recommend following along by trying this Vb Script either on the QTP/UFT software or make a .txt file, type in your code, and rename the .txt to .vbs :

VbScript Syntax Rules:

The statements must fit onto one line; Example:

Outputs:
z


Dim stands for dimension. To declare a variable, such as x, you type “Dim x”. Declaring a variable means that you are telling the Vb program that this variable exists. You can add more with addition signs, “Dim x+y+z” For example:

Outputs:

w


But if you don’t follow the rule that each statement must have it’s separate line, then you can run into an error; Example:

Outputs:
x

What happened here is that MsgBox is not designed to do anything on it’s own, and the same holds true for variable x. That’s why you get an error. But if you combine the two on the same line then you are telling the Vb Script to make a dialog box (MsgBox) that shows the contents of variable x. Alternatively you can directly command Vb Script what to show:

Outputs:
Capture

Continuing Vb Statement on Different Lines

But you can use an underscore to continue your vbScript on a separate line:

Output:


What's Your Opinion?