VBScripting
VBScripting
Variable
Variable
Variable is a memory location w
Variable is a memory location where we can store the values.here we can store the values.
riables are primarily categorized into 2 Types. riables are primarily categorized into 2 Types. Scalar Variables ( It Can Hold Only 1 Value ) Scalar Variables ( It Can Hold Only 1 Value ) Array Variables ( It Can Hold M
Array Variables ( It Can Hold Multiple Value )ultiple Value ) VB Script This Variables are
VB Script This Variables are Further Divided into 2 typesFurther Divided into 2 types Implicit Variable : If a
Implicit Variable : If a Variable is used with out declaring , Variable is used with out declaring , Then itThen it is Called Implicit Variable .
is Called Implicit Variable . Ex: Ex: a=10 a=10 b=20 b=20 c=a+b c=a+b
In the above Program a ,
In the above Program a , b , c b , c are Called Implicit Variable.are Called Implicit Variable. Explicit Variable : If a
Explicit Variable : If a variable is declared and utilized then Thisvariable is declared and utilized then This variables are called Explicit Variable . You Can Declare a Variable variables are called Explicit Variable . You Can Declare a Variable Using Dim . Using Dim . Ex 1 : Ex 1 : Dim a,b,c Dim a,b,c
a=10 a=10 b=20 b=20 c=a+b c=a+b
In the above Program a ,
In the above Program a , b , c are b , c are Called Explicit Variable.Called Explicit Variable. te :
te :
By Default VB Script Allows both
By Default VB Script Allows both implicit and Explicit Variablesimplicit and Explicit Variables Ex 2 : Ex 2 : Dim a,b Dim a,b a=10 a=10 b=20 b=20 c=a+b c=a+b
In the above Program a ,
In the above Program a , b are Called Explicit Variable and c isb are Called Explicit Variable and c is Called Implicit Variable.
Called Implicit Variable. te :
te :
There is a draw back with
There is a draw back with Implicit Variable , i.e. A Spelling MImplicit Variable , i.e. A Spelling Mistakeistake also Consider as a new
also Consider as a new Variable because of this you may getVariable because of this you may get In Correct Results . In Correct Results . Ex 3 : Ex 3 : Dim a,b,c Dim a,b,c a=10 a=10 b=20 b=20 c=a+d c=a+d msgbox c msgbox c
tion Explicit tion Explicit
It Instructs VB Scripting Don¶t
It Instructs VB Scripting Don¶t Allow Implicit Variable.Allow Implicit Variable. Option Explicit statement is specified Then every
Option Explicit statement is specified Then every variable Must bevariable Must be clared before Using that
clared before Using that Variable.Variable. Ex 4 : Ex 4 : Option Explicit Option Explicit Dim a,b,c Dim a,b,c a=10 a=10 b=20 b=20 c=a+d c=a+d msgbox c msgbox c
ou Will get Error in Above Program ou Will get Error in Above Program ray Variable
ray Variable
Array Variables are useful to Store M
Array Variables are useful to Store Multiple Values.ultiple Values. Ex :
Ex : Dim
Dim sname(5) sname(5) - - You You can can not not Resize Resize The The ArrayArray ReDim
ReDim sname(5) sname(5) - - You You can can Resize Resize The The ArrayArray
Ex 1: Ex 1:
Dim sname(5) Dim sname(5)
sname(0)="A" sname(0)="A" sname(1)="B" sname(1)="B" sname(2)="C" sname(2)="C" sname(3)="D" sname(3)="D" sname(4)="E" sname(4)="E" msgbox sname(1) msgbox sname(1) Dim sname(10) Dim sname(10) te : te : It will Produce a
It will Produce a error YBCZ in Dim we Can Not Resizeerror YBCZ in Dim we Can Not Resize Ex 2: Ex 2: ReDim sname(5) ReDim sname(5) sname(0)="A" sname(0)="A" sname(1)="B" sname(1)="B" sname(2)="C" sname(2)="C" sname(3)="D" sname(3)="D" sname(4)="E" sname(4)="E" msgbox sname(1) msgbox sname(1) ReDim sname(10) ReDim sname(10) sname(5)="F" sname(5)="F" msgbox sname(1) msgbox sname(1) te : te :
It will show Null Value in sname(1) YBCZ There Is no Preserve It will show Null Value in sname(1) YBCZ There Is no Preserve Ex : Ex : ReDim sname(5) ReDim sname(5) sname(0)="A" sname(0)="A" sname(1)="B" sname(1)="B" sname(2)="C" sname(2)="C" sname(3)="D" sname(3)="D" sname(4)="E" sname(4)="E" msgbox sname(1) msgbox sname(1)
ReDim preserve sname(10) ReDim preserve sname(10) sname(5)="F" sname(5)="F" msgbox sname(1) msgbox sname(1) Operators Operators Arithmetic Arithmetic Relational Relational Logical Logical Concatenation Concatenation Assignment Assignment Arithmetic Arithmetic + Addition + Addition
- Subtraction - Subtraction * Product * Product / Division / Division Relational Relational = = Equals Equals toto <> Compare <> Compare >
> Greater Greater thenthen <
< Less Less thenthen >=
>= Greater Greater then then or or Equals Equals toto <=
<= Less Less then then or or Equals Equals toto Logical Logical And && And && Or || Or || Not ! Not ! Concatenation Concatenation &
& Concatenate Concatenate Two Two Different Different Data Data Type Type Values.Values. Ex :
Ex :
a=1 a=1
msgbox
Assignment
Assignment
Used to Assign Value to variable and variable to variable Used to Assign Value to variable and variable to variable a = 10 a = 10 a = b a = b VB Script Constant VB Script Constant A Constant Value Can not be
A Constant Value Can not be Changed in the same ActionChanged in the same Action Ex : Ex : const a=10 const a=10 msgbox a msgbox a a=20 a=20 te : te :
It will Produce a error YBCZ a is constant . It will Produce a error YBCZ a is constant .
Built in Functions in VB Script Built in Functions in VB Script
sc sc
eturns the ANSI character code corresponding to the first letter in a eturns the ANSI character code corresponding to the first letter in a
string. string.
sc(
sc(stringstring))
he
he string string argument is any valid string expression. If theargument is any valid string expression. If the string string contains nocontains no
characters, a run-time error occurs. characters, a run-time error occurs.
emarks emarks
the following example,
the following example, AscAsc returns the ANSI character code of the firstreturns the ANSI character code of the first letter of each string:
letter of each string: im MyNumber
im MyNumber yNumber =
yNumber = Asc(Asc("A""A")) ' Returns 65.' Returns 65. yNumber =
yNumber = Asc(Asc("a""a")) ' Returns 97.' Returns 97. yNumber =
yNumber = Asc(Asc("Apple""Apple")) ' Returns 65.' Returns 65.
---hr Function
hr Function
eturns the character associated with the specified ANSI character code. eturns the character associated with the specified ANSI character code.
hr(
hr(charcodecharcode))
he
he chachar r codecode argument is a number that identifies a character.argument is a number that identifies a character. im MyChar
im MyChar yChar =
yChar = Chr(Chr(6565)) ' Returns A.' Returns A. yChar =
yChar = Chr(Chr(9797)) ' Returns a.' Returns a.
---Case Function Case Function
eturns a string that has been converted to uppercase. eturns a string that has been converted to uppercase.
Case(
Case( string string )) he
he string string argument is any valid string expression. If argument is any valid string expression. If string string contains Null,contains Null, ull
ull is returned.is returned.
emarks emarks
nly lowercase letters are converted to uppercase; all uppercase letters and nly lowercase letters are converted to uppercase; all uppercase letters and on-letter characters remain unchanged.
on-letter characters remain unchanged. he following example uses the
he following example uses the UCaseUCase function to return an uppercasefunction to return an uppercase ersion of a string:
ersion of a string: im MyWord
im MyWord yWord =
yWord = UCase(UCase("Hello World""Hello World")) ' Returns "HELLO WORLD".' Returns "HELLO WORLD".
---Case Function
Case Function
eturns a string that has been converted to lowercase. eturns a string that has been converted to lowercase. Case(
Case( string string )) he
he string string argument is any valid string expression. If argument is any valid string expression. If string string contains Null,contains Null,
ull
ull is returned.is returned.
emarks emarks
nly uppercase letters are converted to lowercase; all lowercase letters and nly uppercase letters are converted to lowercase; all lowercase letters and on-letter characters remain unchanged.
on-letter characters remain unchanged. he following example uses the
he following example uses the LCaseLCase function to convert uppercasefunction to convert uppercase tters to lowercase: tters to lowercase: im MyString im MyString im LCaseString im LCaseString yString = "VBSCript" yString = "VBSCript" CaseString =
CaseString = LCase(LCase(MyStringMyString)) ' LCaseString contains "vbscript".' LCaseString contains "vbscript".
---en Function
en Function
eturns the number of characters in a string . eturns the number of characters in a string .
rguments rguments ring
ring
Any valid string expression. If
Any valid string expression. If string string contains Null,contains Null, NullNull is returned.is returned. a
arnrnameame
Any valid variable name. If
Any valid variable name. If vvaarnrname containsame contains NullNull,, NullNull is returned.is returned.
emarks emarks
he following example uses the
he following example uses the LenLen function to return the number of function to return the number of characters in a string:
characters in a string: im MyString
im MyString yString =
---Trim; R---Trim; and Trim Functions
Trim; RTrim; and Trim Functions
eturns a copy of a stri
eturns a copy of a string without leading spaces (ng without leading spaces (LTrimLTrim)), trailing spaces, trailing spaces
Trim
Trim)), or both leading and trailing spaces (, or both leading and trailing spaces (TrimTrim))..
Trim(
Trim(stringstring)) Trim(
Trim(stringstring)) rim(
rim(stringstring))
he
he string string argument is any valid string expression. If argument is any valid string expression. If string string contains Null,contains Null,
ull
ull is returned.is returned.
emarks emarks
he following example uses the
he following example uses the LTrimLTrim,, RTrimRTrim, and, and TrimTrim functions tofunctions to im leading spaces, trailing spaces, and both leading and trailing spaces, im leading spaces, trailing spaces, and both leading and trailing spaces,
spectively: spectively: im MyVar im MyVar
yVar =
yVar = LTrim(LTrim(" " vbscript vbscript "")) ' MyVar contains "vbscript ".' MyVar contains "vbscript ". yVar =
yVar = RTrim(RTrim(" " vbscript vbscript "")) ' ' MyVar MyVar contains contains " " vbscript".vbscript". yVar =
yVar = Trim(Trim(" " vbscript vbscript "")) ' MyVar contains "vbscript".' MyVar contains "vbscript".
---eft Function
eft Function
eturns a specified number of
eft(
eft(stringstring,, lengthlength)) rguments
rguments ring
ring
tring expression from which the leftmost characters are returned. If
tring expression from which the leftmost characters are returned. If string string
ontains Null,
ontains Null, NullNull is returned.is returned.
ngt ngt hh
umeric expression indicating how many characters to return. If 0, a umeric expression indicating how many characters to return. If 0, a zero-ngth string(""
ngth string("")) is returned. If greater than or equal to the is returned. If greater than or equal to the number of number of haracters in
haracters in string string , the entire string is returned., the entire string is returned.
emarks emarks
o determine the number of characters in
o determine the number of characters in string string , use the, use the LenLen function.function. he following example uses the
he following example uses the LeftLeft function to return the first threefunction to return the first three haracters of MyString: haracters of MyString: im MyString, LeftString im MyString, LeftString yString = "VBSCript" yString = "VBSCript" eftString =
eftString = Left(Left(MyString, 3MyString, 3)) ' LeftString contains "VBS".' LeftString contains "VBS".
---ight Function
ight Function
eturns a specified number of
eturns a specified number of characters from the right side of a characters from the right side of a string.string.
ight(
ight(stringstring,, lengthlength)) rguments
ring ring
tring expression from which the rightmost characters are returned. If tring expression from which the rightmost characters are returned. If
ring
ring contains Null,contains Null, NullNull is returned.is returned.
ngt ngt hh
umeric expression indicating how many characters to return. If 0, a umeric expression indicating how many characters to return. If 0, a zero-ngth string is returned. If greater
ngth string is returned. If greater than or equal to the number of than or equal to the number of haracters in
haracters in string string , the entire string is returned., the entire string is returned.
emarks emarks
o determine the number of characters in
o determine the number of characters in string string , use the, use the LenLen function.function. he following example uses the
he following example uses the RightRight function to return a specifiedfunction to return a specified umber of characters from the right side of a string:
umber of characters from the right side of a string: im AnyString, MyStr
im AnyString, MyStr nyString
nyString = = "Hello "Hello World" World" ' ' Define Define string.string. yStr =
yStr = Right(Right(AnyStringAnyString,, 11)) ' Returns "d".' Returns "d". yStr =
yStr = Right(Right(AnyStringAnyString,, 66)) ' Returns " World".' Returns " World". yStr =
yStr = Right(Right(AnyStringAnyString,, 2020)) ' Returns "Hello World".' Returns "Hello World".
---id Function
id Function
eturns a specified number of characters from a string. eturns a specified number of characters from a string.
id(
id(stringstring,, startstart[[,, lengthlength]])) rguments
ring ring
tring expression from which characters are returned. If
tring expression from which characters are returned. If string string containscontains ull,
ull, NullNull is returned.is returned. a
art rt
haracter position in
haracter position in string string at which the part to be taken begins. If at which the part to be taken begins. If st st aart rt isis reater than the number of characters in
reater than the number of characters in string string ,, MidMid returns a zero-lengthreturns a zero-length ring (""
ring (""))..
ngt ngt hh
umber of characters to return. If omitted or if there are fewer than
umber of characters to return. If omitted or if there are fewer than l l eengt ngt hh haracters in the text (including the character at
haracters in the text (including the character at st st aart rt )), all characters from, all characters from ee st st aart rt position to the end of the string are position to the end of the string are returned.returned.
emarks emarks
o determine the number of characters in
o determine the number of characters in string string , use the, use the LenLen function.function. he following example uses the
he following example uses the MidMid function to return six characters,function to return six characters, eginning with the fourth character, in a string:
eginning with the fourth character, in a string: im MyVar
im MyVar yVar =
yVar = Mid(Mid("VB Script is fun!""VB Script is fun!",, 44,, 66)) ' MyVar contains "Script".' MyVar contains "Script".
---putBox Function
putBox Function
isplays a prompt in a dialog box,
isplays a prompt in a dialog box, waits for the user to input text or cwaits for the user to input text or click alick a utton, and returns the contents of the text box.
emarks emarks
the user clicks
the user clicks OK OK or pressesor presses ENTER ENTER , the, the InputBoxInputBox function returnsfunction returns hatever is in the text box. If the user clicks
hatever is in the text box. If the user clicks CancelCancel, the function returns a, the function returns a ero-length string (""
ero-length string (""))..
he following example uses the
he following example uses the InputBoxInputBox function to display an input boxfunction to display an input box nd assign the string to the variable
nd assign the string to the variable Input:Input: im Input
im Input put =
put = InputBox(InputBox("Enter your name""Enter your name"))
sgBox ("You entered: "
sgBox ("You entered: " & Input& Input))
---sgBox Function
sgBox Function
isplays a message in a d
isplays a message in a dialog box, waits for the user to ialog box, waits for the user to click a button, andclick a button, and turns a value indicating which button the user clicked.
turns a value indicating which button the user clicked.
sgBox(
sgBox( prompt prompt))
sgbox ³Hai´ sgbox ³Hai´ ---rint rint
Prints the Specified String or Variable
Prints the Specified String or Variable Value in a Print log with outValue in a Print log with out topping the Execution
topping the Execution x
=10 =10 rint "Welcome" rint "Welcome" rint "Hai" rint "Hai" rint a rint a ---atePart Function atePart Function
eturns the specified part of a given date. eturns the specified part of a given date.
ettings ettings
he
he int int eer r vvaal l argument can have the following values:argument can have the following values:
Setting Description Setting Description yyyy Year yyyy Year q Quarter q Quarter m Month m Month y
y Day Day of of year year
d Day
d Day
w Weekday
w Weekday
ww
ww Week Week of of year year
h Hour h Hour n Minute n Minute s Second s Second x : x : x = DatePart("d", Now( x = DatePart("d", Now()) )) msgbox x msgbox x
---ate Function ate Function
eturns the current system date. eturns the current system date.
emarks emarks
he following example uses the
he following example uses the DateDate function to return the current systemfunction to return the current system ate:
ate:
im MyDate im MyDate
yDate =
yDate = DateDate ' MyDate contains the current system date.' MyDate contains the current system date.
---ime Function
ime Function
eturns a
eturns a VariantVariant of subtypeof subtype DateDate indicating the current system time.indicating the current system time.
emarks emarks
he following example uses the
he following example uses the TimeTime function to return the current systemfunction to return the current system me:
me:
im MyTime im MyTime
yTime =
yTime = TimeTime ' Return current system time.' Return current system time.
---ow
ow
eturns the current date
eturns the current date and time according to the setting of your and time according to the setting of your omputer's system date and time.
omputer's system date and time. ow
emarks emarks
he following example uses the
he following example uses the NowNow function to return the current datefunction to return the current date nd time:
nd time:
im MyVar im MyVar
yVar =
yVar = NowNow ' MyVar contains the current date and time.' MyVar contains the current date and time.
---ateAdd Function
ateAdd Function
eturns a date to which a specified time interval has been added. eturns a date to which a specified time interval has been added.
ateAdd(
ateAdd(intervalinterval,, number number ,, datedate))
he
he int int eer r vvaal l argument can have the following values:argument can have the following values:
Setting Description Setting Description yyyy Year yyyy Year q Quarter q Quarter m Month m Month y
y Day of Day of year year
d Day
d Day
w Weekday
w Weekday
ww
ww Week Week of of year year
h Hour h Hour n Minute n Minute s Second s Second x : x : = DateAdd("m", 1, date()) = DateAdd("m", 1, date())
sgbox x sgbox x ---ateDiff Function ateDiff Function
eturns the number of intervals between two dates. eturns the number of intervals between two dates.
ateDiff(
ateDiff(intervalinterval,, date1date1,, date2date2))
he
he DateDiff DateDiff function syntax has these parts:function syntax has these parts: he
he int int eer r vvaal l argument can have the following values:argument can have the following values:
Setting Description Setting Description yyyy Year yyyy Year q Quarter q Quarter m Month m Month y
y Day Day of of year year
d Day
d Day
w Weekday
w Weekday
ww
ww Week Week of of year year
h Hour h Hour n Minute n Minute s Second s Second x : x : =DateDiff("d", "01/01/09",Date()) =DateDiff("d", "01/01/09",Date()) sgbox x sgbox x
---Int Function Int Function
eturns an expression that has been converted to a
eturns an expression that has been converted to a VariantVariant of subtypeof subtype
teger teger.. x 1: x 1: ="10" ="10" ="20" ="20" sgbox a+b sgbox a+b x 2: x 2: ="10" ="10" ="20" ="20" sgbox cint(a)+cint(b) sgbox cint(a)+cint(b) ---Dbl Function Dbl Function
eturns an expression that has been converted to a
eturns an expression that has been converted to a VariantVariant of subtypeof subtype
ouble ouble.. x 1: x 1: ="10.5" ="10.5" ="20.10" ="20.10" sgbox cint(a)+cint(b) sgbox cint(a)+cint(b)
x 2 : x 2 : ="10.5" ="10.5" ="20.10" ="20.10" sgbox cdbl(a)+cdbl(b) sgbox cdbl(a)+cdbl(b) ---Date Function Date Function
eturns an expression that has been converted to a
eturns an expression that has been converted to a VariantVariant of subtypeof subtype
ate ate.. x : x : =cdate("January 26 2009") =cdate("January 26 2009") sgbox x sgbox x
Conditional Statements in VB Script Conditional Statements in VB Script ) If Then Else
) If Then Else If
If coconnd d itiitioonn ThenThen
[[ st st aat t emeementsnts]]
Else Else
[[eel l s see st st aat t emeementsnts]]
End If End If
) Select Case ) Select Case
it is used to
it is used to execute a block of code out of execute a block of code out of multiple Blocksmultiple Blocks Select Case
Select Case t t ee st st expexpr r ee ssi ssioonn
Case
Case expexpr r ee ssi ssioonnl l ist-nist-n
[[ st st aat t emeements-nnts-n]]
Case
Case expexpr r ee ssi ssioonnl l ist-nist-n
[[ st st aat t emeements-nnts-n]] End Select End Select Loops in VB Scripting Loops in VB Scripting While Loop While Loop
While Loop Execute the Specified Block of stat
While Loop Execute the Specified Block of statementsements r Multiple Iterations when the Specified Condition Remains True, r Multiple Iterations when the Specified Condition Remains True, hen Condition Remains False then the Loop will Exit.
hen Condition Remains False then the Loop will Exit. While
While < < condition condition >> Statements Statements Wend Wend Ex : Ex : Dim i Dim i i=1 i=1 While i<=10 While i<=10 print i print i
i=i+1 i=i+1 Wend Wend Do While Do While Ex : Ex : Dim i Dim i i=50 i=50 Do Do print i print i i=i+1 i=i+1
Loop While i<=10 Loop While i<=10 Exit Do Exit Do Ex : Ex : Dim i Dim i i=1 i=1 Do Do print i print i i=i+1 i=i+1 If i=10 Then If i=10 Then Exit Do Exit Do End If End If
Loop While i<=100 Loop While i<=100
For...Next Statement For...Next Statement
peats a group of state
peats a group of statements a specified number of times.ments a specified number of times.
rr coucount nt eer r == st st aart rt ToTo eennd d [[StepStep st st epep]] [[ st st aat t emeementsnts]]
[[Exit ForExit For]] [[ st st aat t emeementsnts]] xt xt Ex 1: Ex 1: For For i i = = 1 1 to to 55 print i print i Next Next Ex 2 : Ex 2 : For i
For i = = 1 to 1 to 5 step 5 step 22 print i print i Next Next it For it For Ex : Ex :
For i = 1 to 100 For i = 1 to 100 print i print i If i=10 Then If i=10 Then Exit for Exit for End If End If Next Next
User Defined Functions User Defined Functions
Function or Procedure will Contain a set of Statem
Function or Procedure will Contain a set of Statements that ents that areare
signed to Perform a Specific task . Both Functions and Procedures signed to Perform a Specific task . Both Functions and Procedures e Re Usable.
e Re Usable. te :
te :
A Function Returns a Value Where as A Function Returns a Value Where as A Procedure Does Not Return a Value A Procedure Does Not Return a Value 1 : (Function with out
1 : (Function with out ArgumArguments )ents ) Function sum() Function sum() Dim a,b,c Dim a,b,c a=10 a=10 b=20 b=20 c=a+b c=a+b
sum=c sum=c End Function End Function x=sum() x=sum() msgbox x msgbox x 2 :
2 : (Function (Function with with ArgumArguments )ents ) Function sum(x,y) Function sum(x,y) Dim a,b,c Dim a,b,c a=x a=x b=y b=y c=a+b c=a+b sum=c sum=c End Function End Function k=sum(5,2) k=sum(5,2) msgbox k msgbox k For Procedure : For Procedure : Sub sum(x,y) Sub sum(x,y) Dim a,b,c Dim a,b,c a=x a=x b=y b=y c=a+b c=a+b msgbox c msgbox c End Sub End Sub
Call sum(5,2) Call sum(5,2)
On Error Resume Next On Error Resume Next
Script Provided on Error Statement to Enable or Disable
Script Provided on Error Statement to Enable or Disable ErrorError ndling.
ndling.
On Error Goto 0 On Error Goto 0
It disables the error handling
It disables the error handling i.e. What Ever the Error Occurredi.e. What Ever the Error Occurred
During Test Execution That Error will be populated. ( It is Default in During Test Execution That Error will be populated. ( It is Default in VB Scripting )
VB Scripting )
On Error Resume Next On Error Resume Next
It Enables the error handling
It Enables the error handling i.e. The Statement where the Errori.e. The Statement where the Error Occurred During Test Execution That Error will be Skipped and Occurred During Test Execution That Error will be Skipped and QTP Proceeds with next State
QTP Proceeds with next Statemenment Executiont Execution Err.Number
Err.Number It Returns a Corresponding Error Code When It Returns a Corresponding Error Code When a Errora Error is Occur. It Returns 0 , If No Error Occur .
is Occur. It Returns 0 , If No Error Occur . Ex 1:
Ex 1:
On Error Resume Next On Error Resume Next Dim a , b,c Dim a , b,c a=10 a=10 b20 b20 msgbox Err.Number msgbox Err.Number
c=a+b c=a+b print c print c Ex 2: Ex 2:
On Error Resume Next On Error Resume Next Dim a , b,c Dim a , b,c a=10 a=10 b=20 b=20 msgbox Err.Number msgbox Err.Number c=a+b c=a+b print c print c Err.Description
Err.Description It Returns a It Returns a Corresponding Error DescriptionCorresponding Error Description When a Error is Occur. It R
When a Error is Occur. It Returns Null , If No eturns Null , If No Error Occur .Error Occur . Ex :
Ex :
On Error Resume Next On Error Resume Next Dim a , b,c Dim a , b,c a=10 a=10 b20 b20 msgbox Err.
msgbox Err. DescriptionDescription c=a+b
c=a+b print c print c
Ex : Define Error Handling Through Scripting to
Ex : Define Error Handling Through Scripting to Handle the ErrorsHandle the Errors That May Occur When Wrong Fly
That May Occur When Wrong Fly From or Fly to Values SuppliedFrom or Fly to Values Supplied During Insert Order DDT.
Program Program
On Error Resume Next On Error Resume Next Window("Flight
Window("Flight Reservation").AReservation").Activatectivate
Window("Flight Reservation").WinMenu("Men
Window("Flight Reservation").WinMenu("Menu").Select u").Select "File;New Order""File;New Order" Window("Flight
Window("Flight Reservation").AReservation").ActiveX("MctiveX("MaskEdBox").Type askEdBox").Type "010110""010110" Window("Flight Reservation").WinCom
Window("Flight Reservation").WinComboBox("Fly boBox("Fly From:").SelectFrom:").Select datatable(1,1)datatable(1,1) If Err.Number <> 0 Then
If Err.Number <> 0 Then
Window("Flight
Window("Flight Reservation").WReservation").WinCombinComboBox("Fly oBox("Fly From:").Select(From:").Select(0)0)
Err.Number=0
Err.Number=0
Reporter.ReportEvent
Reporter.ReportEvent micWarningmicWarning,,"Fly From""Fly From",,"Incorrect Data in Fly From""Incorrect Data in Fly From"
End If
End If
Window("Flight Reservation").WinCom
Window("Flight Reservation").WinComboBox("Fly boBox("Fly To:").SelectTo:").Select datatable(2,1)datatable(2,1) If E
If Err.Numrr.Number<>0 Thenber<>0 Then
Window("Flight
Window("Flight Reservation").WReservation").WinCombinComboBox("Fly oBox("Fly To:").Select(0)To:").Select(0)
Reporter.ReportEvent
Reporter.ReportEvent micWarningmicWarning,,"Fly To""Fly To",,"Incorrect Data in Fly To""Incorrect Data in Fly To"
End If
End If
Window("Flight
Window("Flight Reservation").WReservation").WinButton("FLIGHT").Click inButton("FLIGHT").Click Window("Flight
Window("Flight Reservation").DReservation").Dialog("Flights ialog("Flights Table").WinButton("OTable").WinButton("OK").Click K").Click Window("Flight
Window("Flight Reservation").WReservation").WinEdit("Name:").Set "Ramesh"inEdit("Name:").Set "Ramesh" Window("Flight