Learn VBScript Step By Step

0
153
Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

VBScript Step By Step
VBScript Step By Step

Introduction of VBScript

This post gives a birds eye view(vbscript basics) documentation on VBscript. This post will cover VBScript for Automation Testing.It gives a brief details about VBScript Tutorial for vbscript learning. If you want to be the master of VBScript, the only best way to learn is to go through several scripts over internet and MSDN document. This post will cover the concepts that we need for Automation testing via UFT.It will also clear your basic vbscript syntax.

The topics to be covered in this tutorials are as follows:

  • Introduction of VBScript
  • Basics of VBScript
  • Create your script from scratch
  • How to enhance your script?
  • Looping in VBscript
  • Conditions in VBScript
  • Data Types in VBScript
  • Variables in VBScript
  • How to Use comments in VBScript?
  • Function and subroutine in VBScript
  • Work with constants in VBScript
  • VBScript documentation standards
  • How to work with VBScript array?
  • What is WSH?- Basic window administration.
  • Introduction to File System Object(FSO)
  • Basic of WMI
  • VBScript Runtime errors and Syntax errors.
  • Debugging VBScripts
  • Error Handling in VBScript
  • Introduction to Dictionary Object
  • Regular expression in VBScript

VBScript for Automation Testing/VBScript Tutorial/vbscript learning/vbscript basics/vbscript syntax

VBScript is an interpreted scripting language. VBScript needs an execution environment in order to execute.

VBScript execution environments-

  • Internet Explorer (Outside of this discussion)
  • WSH(We will discuss)
  • IIs and ASP(Classic)
  • Outlook
  • Microsoft Windows Script console

What is WSH?- Basic window administration.

WSH is the technique by which we can automate many windows related operations.

What WSH can do?

  • Create new user account
  • Managing the windows file system
  • Create shortcuts
  • Managing local drives and printers.
  • Managing network drives and printer.
  • Reporting system and status information.
  • Interact with other application.

How to Use Comment in VbScript?

Comments guide us on what the developer wanted to do with the code i.e the purpose of the code. We can add comments to our statements using an apostrophe (‘), either at the beginning of a separate line or at the end of a statement. It is recommended that we add comments wherever possible, to make our scripts easier to understand and maintain.

Data Types in VBscript

Like any other programing language, VBScript also supports Data types.

Variables in VBScript

VBScript supports variable concept just like any other language. We can specify variables to store strings, integers, arrays, and objects. Using variables helps to make our script more readable and flexible

Work with constants in VBScript

VBScript supports constants of different types.

VBScript Function and Sub Procedure

VBscript allows all to run same and repetitive tasks in the form of functions which can return some value and sub procedure which does not return any value.

Loop and Conditions in VBScript

Using loop and conditions we can put intelligence into the script.

Introduction to File System Object(FSO)

FSO provides us the ability to work with files and folders. FSO will also covers on how to work with folders.

Debugging VBScripts

The art of debugging is an equally important factor while writing VBScript.

Errors and Error Handling in VBScript

Errors and Error handling is another component that whose knowledge minimizes the maintenance effort.

Introduction to Dictionary Object

Dictionary object is the list containing key value pairs.

Regular expression in VBScript

Regular expression in VBScript allows to work with patterns for input and output verifications.

VBScript syntax rules and guidelines

Case-sensitivity:

By default, VBScript is not case sensitive and does not differentiate between uppercase and lowercase spelling of words, for example, in variables, object and method names, or constants.

For example, the two statements below are identical in VBScript:

Browser("Mercury").Page("Find a Flight:").WebList("toDay").Select "31"
browser("mercury").page("find a flight:").weblist("today").select "31"
Text strings:

When we enter a value as a text string, we must add quotation marks before and after the string. For example, in the above segment of script, the names of the Web site, Web page, and edit box are all text strings surrounded by quotation marks.

Note that the value 31 is also surrounded by quotation marks, because it is a text string that represents a number and not a numeric value.

In the following example, only the property name (first argument) is a text string and is in quotation marks. The second argument (the value of the property) is a variable and therefore does not have quotation marks. The third argument (specifying the timeout) is a numeric value, which also does not need quotation marks.

Browser("Mercury").Page("Find a Flight:").WaitProperty("items count", Total_Items, 2000)
Parentheses:

To achieve the desired result and to avoid errors, it is important that we use parentheses () correctly in our statements.

Indentation:

We can indent or outdent our script to reflect the logical structure and nesting of the statements.

Spaces:

We can add extra blank spaces to our script to improve clarity. These spaces are ignored by VBScript.

Input/Output Operations in VBScript

InputBox Function

Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.

Example:

Dim Input
Input = InputBox("Enter your name") 
MsgBox ("You entered: " & Input)
MsgBox Function

Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.

Example:

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")

‘ MyVar contains either 1 or 2, depending on which button is clicked.

 

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here