"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

June 14, 2011

Learning VBScript

For all good reasons :) I'm learning VBScript

From Wikipedia link.
  • VBSB (Visual Basic Scripting Edition)
  • Can be used to write and embed function in web pages
  • Besides javascript, vbscript that can be used to code client-side scripting in a web browser
  • QTP tool uses VBScript
1. Download vbsedit from link. Evaluation version does not expire

2. Get Started with Hello World Example

MsgBox"Hello World"


3. Next is Example using variables and conversions

Dim varTest
'Variable Naming Convention - starts with var
varTest = "12"
MsgBoxTypeName(varTest)
'Convert Variable to Integer
varTest = CInt(varTest)
MsgBoxTypeName(varTest)
4. Next is Prime Number calculation example using functions


OptionExplicit
'Option Explicit - explicitly declare all variables 
Dim varTest
varTest = InputBox("Please Enter Number")
CheckPrime(varTest)
'Function to check for Prime Number
Function CheckPrime(varTest)
Dim i
Dim flag, reminder
flag = 0
i = 2
'Do While Condition Example
Do
 flag = 0
 reminder = varTestMod i
If reminder = 0Then
   MsgBox"Not Prime"
   flag = 1
EndIf   
 i=i+1
LoopWhile flag=0And i<varTest-1     
If flag=0then
MsgBox"Prime Number"
EndIF
EndFunction


5. Next Example is Reading from Excel

Link - Read from Excel

More Reads
Eric Lippert MSDN VBScript Notes
Error Handling in VBScript, Part One
Error Handling In VBScript, Part Two
Error Handling in VBScript, Part Three
VBScript User's Guide


Developing Automation Framework using QTP
Create Test Automation Framework - Introduction
Create Test Automation Framework – Part 1a
Create Test Automation Framework – Part 1b
Create Test Automation Framework – Part 1c


Happy Reading!!

No comments: