Examples of Vbscript

Basic Examples:- 

Scenario 1:– 
To get Output message “Welcome to Vbscript” 

Steps:- 

  • Open any editor(Say Notepad) 
  • Type the code MsgBox(“Welcome to Vbscript”
  • Save file with extension .VBS with Save as Type: All files 
  • Double click the Icon of newly created file.

Output:-


Vbscript Icon UFT
vbscript icon(Double click to run the script)



Vbscript Example Message
Output Message













Note:- Follow the above Steps to create new VBS file each time for new example.

Scenario 2:-
Checking Current Hour of the day. 

Concept:– 
Understand if-Else code 

Code:-

'Taking the Current Hour
Dim iHour
iHour = Hour(time)
'Incase time is less than 12
If iHour < 12 Then
msgbox "Good Morning!! Dude"
else
msgbox "Good Afternoon!! Dude"
End If

Scenario 3:
Taking the specified part form the given string.

Concept:-
Used Mid Function

Syntax of Mid:-
Mid(InputString,Start position,Length(optional))

Code:-

Mid function in UFT
Mid function 

Scenario 4:-
Running the Loop from 1 to 10 in reverse order

Concept:-
Looping using For-Next

Syntax of For-Next loop:-
For Iterator = 1 To 1 Step 1

Next

Code:-

For-Next loop

More Advance Examples
DataTypes in VbScript

Some Key Concepts in VbScript

ufthelp

Leave a Reply

Your email address will not be published. Required fields are marked *