Examples of Vbscript – User friendly Tech help
Basic Examples:-
n
nScenario 1:–
nTo get Output message “Welcome to Vbscript”
n
nSteps:- n
- n
- 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.
n
n
n
n
n
Output:-
n
n
vbscript icon(Double click to run the script) |
n
Output Message |
n
Note:- Follow the above Steps to create new VBS file each time for new example.
n
nScenario 2:-
nChecking Current Hour of the day.
n
nConcept:–
nUnderstand if-Else code
n
nCode:-
n
n
'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
n
Scenario 3:–
nTaking the specified part form the given string.
n
nConcept:-
nUsed Mid Function
n
nSyntax of Mid:-
nMid(InputString,Start position,Length(optional))
n
nCode:-
n
n
Mid function |
n
Scenario 4:-
nRunning the Loop from 1 to 10 in reverse order
n
nConcept:-
nLooping using For-Next
n
nSyntax of For-Next loop:-
nFor Iterator = 1 To 1 Step 1
n
nNext
n
nCode:-
n
For-Next loop |
n
More Advance Examples
nDataTypes in VbScript
n
nSome Key Concepts in VbScript