Sie sind auf Seite 1von 77

Advanced QTP

(In VBScript Orientation)


1) Introduction 2) Comments 3) VB Script Variables 4) VB Script Data Types ) VB Script Operators !) Input"Output Operations #) Constants $) Conditional Statements %) &eneral '(amples 1))*oop T+rou,+ Code 11)-rocedures 12)Built.In /unctions 13)VBScript synta( rules and ,uidelines 14)'rrors 1 )/ile System Operations 1!)Test 0e1uirements 1#) Solutions 1$)2T- 3dd.Ins In4ormation 1%) VBScript &lossary

Introduction
o o o VBScript is a scriptin, lan,ua,e5 3 scriptin, lan,ua,e is a li,+t6ei,+t pro,rammin, lan,ua,e5 VBScript is a li,+t 7ersion o4 8icroso4t9s pro,rammin, lan,ua,e Visual Basic5

:+en a VBScript is inserted into a ;T8* document< t+e Internet bro6ser 6ill read t+e ;T8* and interpret t+e VBScript5 T+e VBScript can be e(ecuted immediately< or at a later e7ent5 8icroso4t Visual Basic Scriptin, 'dition brin,s acti7e scriptin, to a 6ide 7ariety o4 en7ironments< includin, :eb client scriptin, in 8icroso4t Internet '(plorer and :eb ser7er scriptin, in 8icroso4t Internet In4ormation Ser7ice5 1.1 Windows Script Host (WSH) It is a :indo6s administration tool5 :S; creates an en7ironment 4or +ostin, scripts5 T+at is< 6+en a script arri7es at your computer< :S; plays t+e part o4 t+e +ost = it ma>es ob?ects and ser7ices a7ailable 4or t+e script and pro7ides a set o4 ,uidelines 6it+in 6+ic+ t+e script is e(ecuted5 3mon, ot+er t+in,s< :indo6s Script ;ost mana,es security and in7o>es t+e appropriate script en,ine :indo6s Script ;ost is built into 8icroso4t :indo6s %$< 2)))< and 8illennium 'ditions and +i,+er 7ersions5 3 :indo6s script is a te(t 4ile5 :e can create a script 6it+ any te(t editor as lon, as 6e sa7e our script 6it+ a :S;.compatible script e(tension (5?s< 7bs< or 56s4)5 T+e most commonly a7ailable te(t editor is already installed on our computer = @otepad5 :e can also use your 4a7orite ;T8* editor< Vbs'dit< 8icroso4t Visual CAA< or Visual InterDe75 1.2 Creating a script with 15Start @otepad5 25:rite your script5 /or e(ample purposes< type 8s,bo( B;ello VB ScriptB 35Sa7e t+is te(t 4ile 6it+ a 57bs e(tension (instead o4 t+e de4ault 5t(t e(tension)5 /or e(ample< ;ello57bs 45@a7i,ate to t+e 4ile you ?ust sa7ed< and double.clic> it5 5:indo6s Script ;ost in7o>es t+e VB Script en,ine and runs your script5 In t+e e(ample< a messa,e bo( is displayed 6it+ t+e messa,e B;ello VB ScriptB 1.! Hosting "nviron#ents and Script "ngines Scripts are o4ten embedded in :eb pa,es< eit+er in an ;T8* pa,e (on t+e client side) or in an 3S- pa,e (on t+e ser7er side)5 otepad

In t+e case o4 a script embedded in an ;T8* pa,e< t+e en,ine component t+at interprets and runs t+e script code is loaded by t+e :eb bro6ser< suc+ as Internet '(plorer5 In t+e case o4 a script embedded in an 3S- pa,e< t+e en,ine t+at interprets and runs t+e script code is built into Internet In4ormation Ser7ices (IIS)5 :indo6s Script ;ost e(ecutes scripts t+at e(ist outside an ;T8* or 3S- pa,e and t+at stand on t+eir o6n as te(t 4iles5 1.$ Avai%a&%e Script "ngines &enerally< 6e 6rite scripts in eit+er 8icroso4t CScript or VBScript< t+e t6o script en,ines t+at s+ip 6it+ 8icroso4t :indo6s %$< 2))) and 8illennium 'ditions5 :e can use ot+er script en,ines< suc+ as -erl< 0'DD< and -yt+on< 6it+ :indo6s Script ;ost5 3 stand.alone script 6ritten in CScript +as t+e 5?s e(tensionE a stand.alone script 6ritten in VBScript +as t+e 57bs e(tension5 T+ese e(tensions are re,istered 6it+ :indo6s5 :+en 6e run one o4 t+ese types o4 4iles< :indo6s starts :indo6s Script ;ost< 6+ic+ in7o>es t+e associated script en,ine to interpret and run t+e 4ile5

Co##ents
T+e comment ar,ument is t+e te(t o4 any comment 6e 6ant to include5 2.' Purpose o( co##ents) o o :e can use comments 4or ma>in, t+e script understandable5 :e can use comments 4or ma>in, one or more statements disable 4rom e(ecution5

2.1 S*nta+ 0em comment (34ter t+e 0em >ey6ord< a space is re1uired be4ore comment5) Or 3postrop+e (9) symbol be4ore t+e comment 2.2 Co##ent,-nco##ent a &%oc. o( state#ents Select bloc> o4 statement and use s+ort cut >ey Ctrl A 8 (4or comment) Select comment bloc> and use s+ort cut >ey Ctrl A S+i4t A 8 (4or uncomment) 2.! "+a#p%e

/0 Script /aria&%es
3 7ariable is a con7enient place+older t+at re4ers to a computer memory location 6+ere 6e can store pro,ram in4ormation t+at may c+an,e durin, t+e time our script is runnin,5 !.1 1ec%aring /aria&%es :e declare 7ariables e(plicitly in our script usin, t+e Dim statement< t+e -ublic statement< and t+e -ri7ate statement5 /or e(ampleF Dim city Dim ( :e declare multiple 7ariables by separatin, eac+ 7ariable name 6it+ a comma5 /or '(ampleF Dim (< Top< Bottom< *e4t< 0i,+t :e can also declare a 7ariable implicitly by simply usin, its name in our script5 T+at is not ,enerally a ,ood practice because 6e could misspell t+e 7ariable name in one or more places< causin, une(pected results 6+en our script is run5 /or t+at reason< t+e Option '(plicit statement is a7ailable to re1uire e(plicit declaration o4 all 7ariables5 T+e Option '(plicit statement s+ould be t+e 4irst statement in our script5 !.2 2ption "+p%icit /orces e(plicit declaration o4 all 7ariables in a script5 Option '(plicit 9 /orce e(plicit 7ariable declaration5 Dim 8yVar 9 Declare 7ariable5 8yInt G 1) 9 Hndeclared 7ariable ,enerates error5 8yVar G 1) 9 Declared 7ariable does not ,enerate error5 !.! a#ing 3estrictions (or /aria&%es

Variable names 4ollo6 t+e standard rules 4or namin, anyt+in, in VBScript5 3 7ariable nameF o o o o 8ust be,in 6it+ an alp+abetic c+aracter5 Cannot contain an embedded period5 8ust not e(ceed 2 c+aracters5

8ust be uni1ue in t+e scope in 6+ic+ it is declared5

!.$ Scope o( /aria&%es 3 7ariable9s scope is determined by 6+ere 6e declare it5 :+en 6e declare a 7ariable 6it+in a procedure< only code 6it+in t+at procedure can access or c+an,e t+e 7alue o4 t+at 7ariable5 I4 6e declare a 7ariable outside a procedure< 6e ma>e it reco,niIable to all t+e procedures in our script5 T+is is a script.le7el 7ariable< and it +as script.le7el scope5 !.4 5i(e Ti#e o( /aria&%es T+e li4etime o4 a 7ariable depends on +o6 lon, it e(ists5 T+e li4etime o4 a script.le7el 7ariable e(tends 4rom t+e time it is declared until t+e time t+e script is 4inis+ed runnin,5 3t procedure le7el< a 7ariable e(ists only as lon, as you are in t+e procedure5 !.6 Assigning /a%ues to /aria&%es Values are assi,ned to 7ariables creatin, an e(pression as 4ollo6sF T+e 7ariable is on t+e le4t side o4 t+e e(pression and t+e 7alue you 6ant to assi,n to t+e 7ariable is on t+e ri,+t5 /or e(ampleF 3 G 2)) City G J;yderabadK DG1))F LG2)) !.7 Sca%ar /aria&%es and Arra* /aria&%es 3 7ariable containin, a sin,le 7alue is a scalar 7ariable5 3 7ariable containin, a series o4 7alues< is called an array 7ariable5 3rray 7ariables and scalar 7ariables are declared in t+e same 6ay< e(cept t+at t+e declaration o4 an array 7ariable uses parent+eses () 4ollo6in, t+e 7ariable name5 '(ampleF Dim 3(3) 3lt+ou,+ t+e number s+o6n in t+e parent+eses is 3< all arrays in VBScript are Iero. based< so t+is array actually contains 4 elements5 :e assi,n data to eac+ o4 t+e elements o4 t+e array usin, an inde( into t+e array5 Be,innin, at Iero and endin, at 4< data can be assi,ned to t+e elements o4 an array as 4ollo6sF

3()) 3(1) 3(2) 3(3)

G2 ! G 324 G 1)) G

Similarly< t+e data can be retrie7ed 4rom any element usin, an inde( into t+e particular array element you 6ant5 /or e(ampleF SomeVariable G 3(4) 3rrays aren9t limited to a sin,le dimension5 :e can +a7e as many as !) dimensions< alt+ou,+ most people can9t compre+end more t+an t+ree or 4our dimensions5 In t+e 4ollo6in, e(ample< t+e 8yTable 7ariable is a t6o.dimensional array consistin, o4 ! ro6s and 11 columnsF Dim 8yTable( < 1)) In a t6o.dimensional array< t+e 4irst number is al6ays t+e number o4 ro6sE t+e second number is t+e number o4 columns5 !.8 1*na#ic Arra*s :e can also declare an array 6+ose siIe c+an,es durin, t+e time our script is runnin,5 T+is is called a dynamic array5 T+e array is initially declared 6it+in a procedure usin, eit+er t+e Dim statement or usin, t+e 0eDim statement5 ;o6e7er< 4or a dynamic array< no siIe or number o4 dimensions is placed inside t+e parent+eses5 /or e(ampleF Dim 8y3rray() 0eDim 3not+er3rray() To use a dynamic array< you must subse1uently use 0eDim to determine t+e number o4 dimensions and t+e siIe o4 eac+ dimension5 In t+e 4ollo6in, e(ample< 0eDim sets t+e initial siIe o4 t+e dynamic array to 2 5 3 subse1uent 0eDim statement resiIes t+e array to 3)< but uses t+e -reser7e >ey6ord to preser7e t+e contents o4 t+e array as t+e resiIin, ta>es place5 0eDim 8y3rray(2 ) 0eDim -reser7e 8y3rray(3)) T+ere is no limit to t+e number o4 times 6e can resiIe a dynamic array< alt+ou,+ i4 6e ma>e an array smaller< 6e lose t+e data in t+e eliminated elements5

/0 Script 1ata T*pes


VBScript +as only one data type called a Variant5 3 Variant is a special >ind o4 data type t+at can contain di44erent >inds o4 in4ormation< dependin, on +o6 it is used5 Because Variant is t+e only data type in VBScript< it is also t+e data type returned by all 4unctions in VBScript5 $.1 /ariant Su&t*pes Beyond t+e simple numeric or strin, classi4ications< a Variant can ma>e 4urt+er distinctions about t+e speci4ic nature o4 numeric in4ormation5 /or e(ample< 6e can +a7e numeric in4ormation t+at represents a date or a time5 :+en used 6it+ ot+er date or time data< t+e result is al6ays e(pressed as a date or a time5 :e can also +a7e a ric+ 7ariety o4 numeric in4ormation ran,in, in siIe 4rom Boolean 7alues to +u,e 4loatin,.point numbers5 T+ese di44erent cate,ories o4 in4ormation t+at can be contained in a Variant are called subtypes5 8ost o4 t+e time< 6e can ?ust put t+e >ind o4 data 6e 6ant in a Variant< and t+e Variant be+a7es in a 6ay t+at is most appropriate 4or t+e data it contains5 T+e 4ollo6in, table s+o6s subtypes o4 data t+at a Variant can contain5 Subtype Description 'mpty Variant is uninitialiIed5 Value is ) 4or numeric 7ariables or a Iero.len,t+ strin, (BB) 4or strin, 7ariables5 @ull Variant intentionally contains no 7alid data5 Boolean Contains eit+er True or /alse5 Byte Contains inte,er in t+e ran,e ) to 2 5 Inte,er Contains inte,er in t+e ran,e .32<#!$ to 32<#!#5 Currency .%22<33#<2)3<!$ <4##5 $)$ to %22<33#<2)3<!$ <4##5 $)#5 *on, Contains inte,er in t+e ran,e .2<14#<4$3<!4$ to 2<14#<4$3<!4#5 Sin,le Contains a sin,le.precision< 4loatin,.point number in t+e ran,e .354)2$23'3$ to .154)12%$'.4 4or ne,ati7e 7aluesE 154)12%$'.4 to 354)2$23'3$ 4or positi7e 7alues5 Double Contains a double.precision< 4loatin,.point number in t+e ran,e .15#%#!%3134$!232'3)$ to .45%4)! !4 $4124#'.324 4or ne,ati7e 7aluesE 45%4)! !4 $4124#'.324 to 15#%#!%3134$!232'3)$ 4or positi7e 7alues5 Date (Time) Contains a number t+at represents a date bet6een Canuary 1< 1)) to December 31< %%%%5 Strin, Contains a 7ariable.len,t+ strin, t+at can be up to appro(imately 2 billion c+aracters in len,t+5 Ob?ect Contains an ob?ect5 'rror Contains an error number5 :e can use con7ersion 4unctions to con7ert data 4rom one subtype to anot+er5 In addition< t+e VarType 4unction returns in4ormation about +o6 your data is stored 6it+in a Variant5

/0 Script 2perators
Operators are used 4or per4ormin, mat+ematical< comparison and lo,ical operations5 VBScript +as a 4ull ran,e o4 operators< includin, arit+metic operators< comparison operators< concatenation operators< and lo,ical operators5 $.1 2perator Precedence :+en se7eral operations occur in an e(pression< eac+ part is e7aluated and resol7ed in a predetermined order called operator precedence5 :e can use parent+eses to o7erride t+e order o4 precedence and 4orce some parts o4 an e(pression to be e7aluated be4ore ot+ers5 Operations 6it+in parent+eses are al6ays per4ormed be4ore t+ose outside5 :it+in parent+eses< +o6e7er< standard operator precedence is maintained5 :+en e(pressions contain operators 4rom more t+an one cate,ory< arit+metic operators are e7aluated 4irst< comparison operators are e7aluated ne(t< and lo,ical operators are e7aluated last5 Comparison operators all +a7e e1ual precedenceE t+at is< t+ey are e7aluated in t+e le4t.to.ri,+t order in 6+ic+ t+ey appear5 3rit+metic and lo,ical operators are e7aluated in t+e 4ollo6in, order o4 precedence5 $.2 Arith#etic 2perators) 2perator 1) '(ponentiation Operator (M) 2) 8ultiplication Operator (N) 3) Di7ision Operator (") 4) ) !) #) Inte,er Di7ision Operator (O) 8od Operator 3ddition Operator (A) Subtraction Operator (.) 1escription 0aises a number to t+e po6er o4 an e(ponent 8ultiplies t6o numbers5 Di7ides t6o numbers and returns a 4loatin,.point result5 Di7ides t6o numbers and returns an inte,er result5 Di7ides t6o numbers and returns only t+e remainder5 Sums t6o numbers5 /inds t+e di44erence bet6een t6o numbers or indicates t+e ne,ati7e 7alue o4 a numeric e(pression5 /orces strin, concatenation o4 t6o e(pressions5

$) Concatenation Operator (P) $.! Co#parison 2perators Hsed to compare e(pressions5 Operator 1) G ('1ual to) 2) QR (@ot e1ual to) 3) Q *ess t+an 4) R &rater t+an ) QG *ess t+an or e1ual to

1escription Hsed to compare e(pressions5 Hsed to compare e(pressions5

!) RG &reater t+an or e1ual to #) Is $.$ Concatenation 2perators 2perator 1) 3ddition Operator (9)

Ob?ect e1ui7alence

2) Concatenation Operator (:)

1escription Sums t6o numbers I( Then 1) Bot+ e(pressions are numeric 3dd5 2) Bot+ e(pressions are strin,s Concatenate5 3) One e(pression is numeric and t+e 3dd5 ot+er is a strin, /orces strin, concatenation o4 t6o e(pressions5

$.4 5ogica% 2perators 2perator 1) @ot 2) 3nd 3) Or 4) Dor ) '17 !) Imp 1escription -er4orms lo,ical ne,ation on an e(pression -er4orms a lo,ical con?unction on t6o e(pressions5 -er4orms a lo,ical dis?unction on t6o e(pressions5 -er4orms a lo,ical e(clusion on t6o e(pressions5 -er4orms a lo,ical e1ui7alence on t6o e(pressions5 -er4orms a lo,ical implication on t6o e(pressions5 S*nta+ resultG @ot e(pression resultG e(pression1 e(pression2 resultG e(pression1 e(pression2 resultG e(pression1 e(pression2 resultG e(pression1 e(pression2 3nd Or Dor '17

resultG e(pression1 Imp e(pression2

10

Input,2utput 2perations
6.1 Input0o+ ;unction Displays a prompt in a dialo, bo(< 6aits 4or t+e user to input te(t or clic> a button< and returns t+e contents o4 t+e te(t bo(5 '(ampleF Dim Input Input G InputBo((B'nter your nameB) 8s,Bo( (BLou enteredF B P Input) 6.2 <sg0o+ ;unction Displays a messa,e in a dialo, bo(< 6aits 4or t+e user to clic> a button< and returns a 7alue indicatin, 6+ic+ button t+e user clic>ed5 '(ampleF Dim 8yVar 8yVar G 8s,Bo( (B;ello :orldSB< ! < B8s,Bo( '(ampleB) 9 8yVar contains eit+er 1 or 2< dependin, on 6+ic+ button is clic>ed5

11

/0 Script Constants
3 constant is a meanin,4ul name t+at ta>es t+e place o4 a number or strin, and ne7er c+an,es5 7.1 Creating Constants :e create user.de4ined constants in VBScript usin, t+e Const statement5 Hsin, t+e Const statement< 6e can create strin, or numeric constants 6it+ meanin,4ul names and assi,n t+em literal 7alues5 Const state#ent Declares constants 4or use in place o4 literal 7alues5 '(ampleF Const 8yStrin, G BT+is is my strin,5B Const 8y3,e G 4% Const Cuto44Date G T!.1.%#T @ote t+at Strin, literal is enclosed in 1uotation mar>s (B B)5 0epresent Date literals and time literals by enclosin, t+em in number si,ns (T)5 :e declare multiple constants by separatin, eac+ constant name and 7alue 6it+ a comma5 /or e(ampleF Const priceG 1))< cityG J;yderabadK< (G 2#

12

Conditiona% State#ents
:e can control t+e 4lo6 o4 our script 6it+ conditional statements and loopin, statements5 Hsin, conditional statements< 6e can 6rite VBScript code t+at ma>es decisions and repeats actions5 T+e 4ollo6in, conditional statements are a7ailable in VBScriptF

1) I(=Then="%se State#ent 2) Se%ect Case State#ent 8.1 <a.ing 1ecisions -sing I(...Then..."%se
T+e I4555T+en555'lse statement is used to e7aluate 6+et+er a condition is True or /alse and< dependin, on t+e result< to speci4y one or more statements to run5 Hsually t+e condition is an e(pression t+at uses a comparison operator to compare one 7alue or 7ariable 6it+ anot+er5 I4555T+en555'lse statements can be nested to as many le7els as you need5 8.1.1 3unning a State#ent i( a Condition is True (sing%e state#ent) To run only one statement 6+en a condition is True< use t+e sin,le.line synta( 4or t+e I4555T+en555'lse statement5 Dim myDate myDate G T2"13"%$T I4 myDate Q @o6 T+en myDate G @o6 8.1.2 3unning State#ents i( a Condition is True (#u%tip%e state#ents) To run more t+an one line o4 code< 6e must use t+e multiple.line (or bloc>) synta(5 T+is synta( includes t+e 'nd I4 statement5 Dim ( (G 2) I4 (R1) T+en ms,bo( B;ello &5C50eddyB ms,bo( B( 7alue isF BP( ms,bo( BBye ByeB 'nd I4 8.1.! 3unning Certain State#ents i( a Condition is True and 3unning 2thers i( a Condition is ;a%se :e can use an I4555T+en555'lse statement to de4ine t6o bloc>s o4 e(ecutable statementsF one bloc> to run i4 t+e condition is True< t+e ot+er bloc> to run i4 t+e condition is /alse5 '(ampleF

13

Dim ( (G Inputbo( (B 'nter a 7alueB) I4 (R1)) T+en 8s,bo( B;ello &5C50eddyB 8s,bo( BD is a Bi, @umberB 8s,bo( BD 7alue isF BPD 'lse 8s,bo( B&C0B 8s,bo( BD is a Small @umberB 8s,bo( BD 7alue isF BPD 'nd I4 8.1.$ 1eciding 0etween Severa% A%ternatives 3 7ariation on t+e I4555T+en555'lse statement allo6s us to c+oose 4rom se7eral alternati7es5 3ddin, 'lseI4 clauses e(pands t+e 4unctionality o4 t+e I4555T+en555'lse statement so 6e can control pro,ram 4lo6 based on di44erent possibilities5 '(ampleF Dim ( (G Inputbo( (B 'nter a 7alueB) I4 (R) and (QG1)) T+en 8s,bo( B;ello &5C50eddyB 8s,bo( BD is a Small @umberB 8s,bo( BD 7alue is BP( 'lse I/ (R1)) and (QG )) T+en 8s,bo( B;ello &C0B 8s,bo( BD is a 8edium @umberB 'lse I/ (R )) and (QG1))) T+en 8s,bo( B;ello C+andra 8o+an 0eddyB 8s,bo( BD is a *ar,e @umberB 'lse 'nd I4 'nd I4 'nd I4 8s,bo( B;ello SirB 8s,bo( BD is a &rand @umberB

8.1.4 "+ecuting a certain &%oc. o( state#ents when two , #ore conditions are True ( ested I(...) '(ampleF Dim State< 0e,ion StateGInputbo( (B'nter a StateB) 0e,ionGInputbo( (B'nter a 0e,ionB) I4 stateG B3-B T+en I4 0e,ionG BTelan,anaB T+en

14

ms,bo( B;ello &5C50eddyB ms,bo( BDist count is 1)B 'lse i4 0e,ionG B0ayalasemaB T+en ms,bo( B;ello &C0B ms,bo( BDist count is 4B 'lse I4 0e,ionG BCostalB T+en ms,bo( B;ello C+andra mo+an 0eddyB ms,bo( BDist count is %B 'nd 'nd 'nd 'nd I4 I4 I4 I4

8.2 <a.ing 1ecisions with Se%ect Case


T+e Select Case structure pro7ides an alternati7e to I4555T+en555'lseI4 4or selecti7ely e(ecutin, one bloc> o4 statements 4rom amon, multiple bloc>s o4 statements5 3 Select Case statement pro7ides capability similar to t+e I4555T+en555'lse statement< but it ma>es code more e44icient and readable5 '(ampleF Option e(plicit Dim (<y< Operation< 0esult (G Inputbo( (B 'nter ( 7alueB) yG Inputbo( (B'nter y 7alueB) OperationG Inputbo( (B'nter an OperationB) Select Case Operation Case BaddB 0esultG cdbl (()Acdbl (y) 8s,bo( B;ello &5C50eddyB 8s,bo( B3ddition o4 (<y 7alues is BP0esult 0esultG (.y 8s,bo( B;ello &5C50eddyB 8s,bo( BSubstraction o4 (<y 7alues is BP0esult Case BmulB 0esultG (Ny 8s,bo( B;ello &5C50eddyB 8s,bo( B8ultiplication o4 (<y 7alues is BP0esult 0esultG ("y 8s,bo( B;ello &5C50eddyB 8s,bo( BDi7ision o4 (<y 7alues is BP0esult

Case BsubB

Case Bdi7B

15

Case BmodB

0esultG ( mod y 8s,bo( B;ello &5C50eddyB 8s,bo( B8od o4 (<y 7alues is BP0esult 0esultG (My 8s,bo( B;ello &5C50eddyB 8s,bo(B'(ponentation o4 (<y 7alues is BP0esult

Case Be(poB

Case 'lse

8s,bo( B;ello &5C50eddyB ms,bo( B:ron, OperationB

'nd Select

8.! 2ther "+a#p%es


8.!.1 Write a progra# (or (inding out whether the given *ear is a %eap *ear or not> Dim (year (yearGinputbo( (B'nter LearB) I4 (year mod 4G) T+en ms,bo( BT+is is a *eap yearB 'lse ms,bo( BT+is is @OTB 'nd I4 8.!.2 Write a progra# (or (inding out whether the given nu#&er is? "ven nu#&er or 2dd nu#&er> Dim num numGinputbo( (B'nter a numberB) I4 num mod 2G) T+en ms,bo( BT+is is a '7en @umberB 'lse ms,bo( BT+is is a Odd @umberB 'nd I4 $5353 0ead t6o numbers and display t+e sumU Dim num1<num2< sum num1Ginputbo( (B'nter num1B) num2Ginputbo( (B'nter num2B) re1uire sumG Cdbl (num1) A Cdbl (num2) 9i4 6e 6ant add t6o strin,s con7ersion ms,bo( (BSum is B Psum)

16

8.!.$ 3ead P?T?3 va%ues and Ca%cu%ate the Si#p%e Interest> Dim p<t< r< si pGinputbo( (B'nter -rincipleB) tGinputbo( (B'nter TimeB) rGinputbo( (B'nter 0ate o4 InterestB) siG (pNtNr)"1)) 9 pG principle amount< tGtime in years< rG rate o4 interest ms,bo( (BSimple Interest is B Psi) 8.!.4 3ead ;our digit nu#&er? ca%cu%ate : disp%a* the su# o( the nu#&er or disp%a* "rror #essage i( the nu#&er is not a (our digit nu#&er> Dim num< sum numGinputbo( (B'nter a /our di,it numberB) I4 *en(num) G 4 T+en sumG) sumGsumAnum mod 1) numGnum"1) numG le4t (num< 3) sumGsumAnum mod 1) numGnum"1) numG le4t (num< 2) sumGsumAnum mod 1) numGnum"1) numG le4t (num< 1) sumGsumAnum mod 1) ms,bo( (BSum is B Psum) else ms,bo( B@umber< you entered is not a 4 di,it numberB 'nd I4 8.!.6 3ead an* ;our@digit nu#&er and disp%a* the nu#&er in reverse order> Dim num<re7 numG inputbo((B'nter a numberB) I4 len(num)G4 T+en re7Gre7N1) A num mod 1) numGnum"1) numG le4t(num<3) re7Gre7N1) A num mod 1) numGnum"1) numG le4t(num<2) re7Gre7N1) A num mod 1) numGnum"1) numG le4t(num<1) re7Gre7N1) A num mod 1) ms,bo( B0e7erse Order o4 t+e number is BPre7

17

'lse 'nd I4

ms,bo( B@umber< you entered is not a 4 di,it numberB

8.!.7 3ead $ su&Aects #ar.sB ca%cu%ate the Tota% #ar.s and grade> (a) I4 a7era,e mar>s &reater t+an or e1ual to # < ,rade is Distinction b) I4 a7era,e mar>s &reater t+an or e1ual to !) and less t+an # < t+en ,rade is /irst c) I4 a7era,e mar>s &reater t+an or e1ual to ) and less t+an !) < t+en ,rade is Second d) I4 a7era,e mar>s &reater t+an or e1ual to 4) and less t+an ) < t+en ,rade is T+ird e) 8inimum mar>s 3 4or any sub?ect< ot+er6ise 9no ,rade 4ail9) Dim e<m<p<c< tot eGinputbo( (B'nter en,lis+ 8ar>sB) mGinputbo( (B'nter mat+s 8ar>sB) pGinputbo( (B'nter p+ysics 8ar>sB) cGinputbo( (B'nter c+emistry 8ar>sB) totG cdbl(e) A cdbl(m) A cdbl(p) A cdbl(c) ms,bo( tot I4 cdbl(e) RG3 and cdbl(m) RG3 and cdbl(p) RG3 and cdbl(c) RG3 and tot RG3)) T+en ms,bo( B&rade is DistinctionB else I4 cdbl(e) RG3 and cdbl(m) RG3 and cdbl(p) RG3 and cdbl(c) RG3 and tot RG24) and totQ3)) T+en ms,bo( B&rade is /irstB else I4 cdbl(e) RG3 and cdbl(m) RG3 and cdbl(p) RG3 and cdbl(c) RG3 and tot RG2)) and totQ24) T+en ms,bo( B&rade is SecondB else I4 cdbl(e) RG3 and cdbl(m) RG3 and cdbl(p) RG3 and cdbl(c) RG3 and tot RG1!) and totQ2)) T+en ms,bo( B&rade is T+irdB else ms,bo( B@o &rade< /ailB 'nd 'nd 'nd 'nd I4 I4 I4 I4

8.!.8 1isp%a* 2dd nu#&ers up to n> Dim num<n nGInputbo( (B'nter a VauleB) /or numG 1 to n step 2

18

ms,bo( num @e(t 8.!.C 1isp%a* "ven nu#&ers up to n> Dim num<n nGInputbo( (B'nter a VauleB) /or numG 2 to n step 2 ms,bo( num @e(t 8.!.1' disp%a* natura% nu#&ers up to n and write in a te+t (i%e> Dim num< n< 4so< my4ile nG inputbo( (B'nter any ValueB) numG1 /or numG 1 to n step 1 Set 4soG createob?ect (Bscriptin,54ilesystemob?ectB) set my4ileG4so5opente(t4ile (B'FO,cr5t(tB< $< true) my4ile56riteline num my4ile5close @e(t 8.11 1isp%a* atura% nu#&ers in reverse order up to n>

Dim num<n nGInputbo( (B'nter a VauleB) /or numGn to 1 step .1 ms,bo( num @e(t 8.12 1isp%a* atura% nu#&ers su# up to n> (-sing ;or... e+t 5oop)

Dim num< n< sum nG inputbo( (B'nter a ValueB) sumG) /or numG 1 to n step 1 sumG sumAnum @e(t ms,bo( sum 8.1! 1isp%a* atura% nu#&ers su# up to n> (using Whi%e...Wend 5oop)

Dim num< n< sum nG inputbo( (B'nter a ValueB) :+ile num QGcdbl (n) sumG sumAnum numGnumA1 :end ms,bo( sum

19

8.1$ 1isp%a*

atura% nu#&ers su# up to n> (-sing 1o...-nti%...5oop)

Dim num< n< sum nG inputbo( (B'nter a ValueB) sumG) numG1 Do sumG sumAnum numGnumA1 *oop Hntil num Gcdbl (nA1) ms,bo( sum 8.14 Write a ;unction (or /unction @@umCou (n) Dim num< sum sumG) /or numG 1 to n step 1 sumG sumAnum @e(t ms,bo( sum 'nd /unction 8.16 /eri(* weather the entered 1' digit va%ue is a nu#eric va%ue or not> Dim a<(<y<I<num numGInputbo( (B'nter a -+one @umberB) d1G le4t (num<1) d1)G0i,+t (num<1) d2Gmid (num< 2< len d3Gmid (num< 3< len d4Gmid (num< 4< len d Gmid (num< < len d!Gmid (num< !< len d#Gmid (num< #< len d$Gmid (num< $< len d%Gmid (num< %< len atura% u#&ers su# up to n>

(1)) (1)) (1)) (1)) (1)) (1)) (1)) (1))

I4 isnumeric (d1) G BTrueB and isnumeric (d2) G BTrueB and isnumeric (d3) G BTrueB and isnumeric (d4) G BTrueBand isnumeric (d ) G BTrueBand isnumeric (d!) G BTrueBand isnumeric (d#) G BTrueBand isnumeric (d$) G BTrueBand isnumeric (d%) G BTrueBand isnumeric (d1)) G BTrueB T+en ms,bo( BIt is a @umeric ValueB else 8s,bo( BIt is @OT @umericB 'nd I4

20

8.17 /eri(* weather the entered va%ue is a 1' digit va%ue or not and va%ue or not> (-sing #u%tip%e i( conditions) Dim a<(<y<I<num numGInputbo( (B'nter a -+one @umberB) d1G le4t (num<1) d1)G0i,+t (num<1) d2Gmid (num< 2< len d3Gmid (num< 3< len d4Gmid (num< 4< len d Gmid (num< < len d!Gmid (num< !< len d#Gmid (num< #< len d$Gmid (num< $< len d%Gmid (num< %< len

u#eric

(1)) (1)) (1)) (1)) (1)) (1)) (1)) (1))

I4 len (num) G1) T+en I4 isnumeric (d1) G BTrueB and isnumeric (d2) G BTrueB and isnumeric (d3) G BTrueB and isnumeric (d4) G BTrueBand isnumeric (d ) G BTrueBand isnumeric (d!) G BTrueBand isnumeric (d#) G BTrueBand isnumeric (d$) G BTrueBand isnumeric (d%) G BTrueBand isnumeric (d1)) G BTrueB T+en ms,bo( BIt is a @umeric ValueB 'nd I4 'nd I4 I4 len (num) QR 1) T+en 8s,bo( BIt is @OT 7alid @umber B 'nd I4

21

5ooping Through Code


o o o o *oopin, allo6s us to run a ,roup o4 statements repeatedly5 Some loops repeat statements until a condition is /alseE Ot+ers repeat statements until a condition is True5 T+ere are also loops t+at repeat statements a speci4ic number o4 times5

The (o%%owing %ooping state#ents are avai%a&%e in /0Script) o o o o 1o...5oop) *oops 6+ile or until a condition is True5 Whi%e...Wend) *oops 6+ile a condition is True5 ;or... e+t) Hses a counter to run statements a speci4ied number o4 times5 ;or "ach... e+t) 0epeats a ,roup o4 statements 4or eac+ item in a collection or eac+ element o4 an array5

C.1 -sing 1o 5oops :e can use Do555*oop statements to run a bloc> o4 statements an inde4inite number o4 times5 T+e statements are repeated eit+er 6+ile a condition is True or until a condition becomes True5 C.1.1 3epeating State#ents Whi%e a Condition is True 0epeats a bloc> o4 statements 6+ile a condition is True or until a condition becomes True a) Do :+ile condition Statements ........... ........... *oop Or< 6e can use t+is belo6 synta(F "+a#p%e) Dim ( Do :+ile (Q (G(A1 8s,bo( B;ello &5C50eddyB 8s,bo( B;ello 2T-B *oop b) Do Statements ........... ........... *oop :+ile condition

22

"+a#p%e) Dim ( (G1 Do 8s,bo( B;ello &5C50eddyB 8s,bo( B;ello 2T-B (G(A1 *oop :+ile (Q C.1.2 3epeating a State#ent -nti% a Condition 0eco#es True c) Do Hntil condition Statements ........... ........... *oop Or< 6e can use t+is belo6 synta(F '(ampleF Dim ( Do Hntil (G (G(A1 8s,bo( B&5C50eddyB 8s,bo( B;ello 2T-B *oop Or< 6e can use t+is belo6 synta(F d) Do Statements ........... ........... *oop Hntil condition Or< 6e can use t+is belo6 synta(F "+a#p%e) Dim ( (G1 Do 8s,bo( J;ello &5C50eddyK 8s,bo( B;ello 2T-B (G(A1 *oop Hntil (G C.2 Whi%e...Wend State#ent '(ecutes a series o4 statements as lon, as a ,i7en condition is True5 Synta(F :+ile condition Statements ...........

23

........... :end "+a#p%e) Dim ( (G) :+ile (Q (G(A1 ms,bo( B;ello &5C50eddyB ms,bo( B;ello 2T-B :end C.! ;or... e+t State#ent 0epeats a ,roup o4 statements a speci4ied number o4 times5 Synta(F /or counter G start to end VStep stepW statements @e(t "+a#p%e) Dim ( /or (G 1 to step 1 8s,bo( B;ello &5C50eddyB @e(t C.$ ;or "ach... e+t State#ent 0epeats a ,roup o4 statements 4or eac+ element in an array or collection5 Synta(F /or 'ac+ item In array Statements @e(t '(ampleF (1 Dim a<b<( (3) aG2) bG3) (())G B3ddition is BP aAb ((1)GBSubstraction is B P a.b ((2)G B8ultiplication is B P aNb ((3)G BDi7ision is B P a"b /or 'ac+ element In ( ms,bo( element @e(t '(ampleF (2 8y3rray G 3rray(BoneB<Bt6oB<Bt+reeB<B4ourB<B4i7eB) /or 'ac+ element In 8y3rray

24

@e(t

ms,bo( element

Contro% ;%ow "+a#p%es (-sing Conditiona% and 5oop State#ents)


11.1 read a nu#&er and veri(* that nu#&er 3ange weather in &etween 1 to 1'' or 1'1 to 1'''> Option e(plicit Dim a<( aGInputbo( (B'nter a VauleB) aGcdbl(a) I4 aQG 1)) T+en /or (G 1 to 1)) I4 aG( T+en ms,bo( Ba is in bet6een 1 to 1)) ran,eB 'nd I4 @e(t else /or (G 1)1 to 1))) I4 aG( T+en ms,bo( Ba is in bet6een 1)1 to 1))) ran,eB 'nd I4 @e(t 'nd I4 11.1 read 1ata and (ind that data siDe? I( siDe EF$ then disp%a* inva%id data #essage? i( data siDe G $ then veri(* HaI is there or not in that data> Dim ( (GInputbo( (B'nter 4 di,it 7alueB) (1G0i,+t((<1) (2G*e4t ((<1) (3Gmid ((<2<*en(1)) (4Gmid ((<3<*en(1)) yGlen(() I4 yG4 T+en I4 (1GBaB or (2GBaB or (3GBaB or (4GBaB T+en ms,bo( Ba is t+ereB else ms,bo( Ba is @ot t+ereB 'nd I4 else ms,bo( BIn7alid DataB 'nd I4

25

/0 Script Procedures
In VBScript< t+ere are t6o >inds o4 procedures a7ailableE t+e Su& procedure and t+e ;unction procedure5 11.1 Su& Procedures 3 Sub procedure is a series o4 VBScript statements (enclosed by Sub and 'nd Sub statements) t+at per4orm actions but don9t return a 7alue5 3 Sub procedure can ta>e ar,uments (constants< 7ariables< or e(pressions t+at are passed by a callin, procedure)5 I4 a Sub procedure +as no ar,uments< its Sub statement must include an empty set o4 parent+eses ()5 Synta(F Sub -rocedure name () Statements ........... ........... 'nd Sub Or Sub -rocedure name (ar,ument1< ar,ument2) Statements ........... ........... 'nd Sub "+a#p%e) 1 Sub Con7ertTemp() temp G InputBo((B-lease enter t+e temperature in de,rees /5B< 1) 8s,Bo( BT+e temperature is B P Celsius(temp) P B de,rees C5B 'nd Sub "+a#p%e) 2 11.2 ;unction Procedures 3 /unction procedure is a series o4 VBScript statements enclosed by t+e /unction and 'nd /unction statements5 3 /unction procedure is similar to a Sub procedure< but can also return a 7alue5 3 /unction procedure can ta>e ar,uments (constants< 7ariables< or e(pressions t+at are passed to it by a callin, procedure)5 I4 a /unction procedure +as no ar,uments< its /unction statement must include an empty set o4 parent+eses5

26

3 /unction returns a 7alue by assi,nin, a 7alue to its name in one or more statements o4 t+e procedure5 T+e return type o4 a /unction is al6ays a Variant5 Synta(F /unction -rocedure name () Statements ........... ........... 'nd /unction Or /unction -rocedure name (ar,ument1< ar,ument2) Statements ........... ........... 'nd /unction "+a#p%e) 1 /unction Celsius(4De,rees) Celsius G (4De,rees . 32) N 'nd /unction "+a#p%e) 2 /unction cal(a<b<c) cal G (aAbAc) 'nd /unction 11.! Jetting 1ata into and out o( Procedures o o o o 'ac+ piece o4 data is passed into our procedures usin, an ar,ument5 3r,uments ser7e as place+olders 4or t+e data 6e 6ant to pass into our procedure5 :e can name our ar,uments any 7alid 7ariable name5 :+en 6e create a procedure usin, eit+er t+e Sub statement or t+e /unction statement< parent+eses must be included a4ter t+e name o4 t+e procedure5 3ny ar,uments are placed inside t+ese parent+eses< separated by commas5 "%

11.$ -sing Su& and ;unction Procedures in Code 3 /unction in our code must al6ays be used on t+e ri,+t side o4 a 7ariable assi,nment or in an e(pression5 /or e(ampleF Temp G Celsius(4De,rees) .Or. 8s,Bo( BT+e Celsius temperature is B P Celsius(4De,rees) P B de,rees5B To call a Sub procedure 4rom anot+er procedure< type t+e name o4 t+e procedure alon, 6it+ 7alues 4or any re1uired ar,uments< eac+ separated by a comma5

27

T+e Call statement is not re1uired< but i4 you do use it< you must enclose any ar,uments in parent+eses5 T+e 4ollo6in, e(ample s+o6s t6o calls to t+e 8y-roc procedure5 One uses t+e Call statement in t+e codeE t+e ot+er doesn9t5 Bot+ do e(actly t+e same t+in,5 Call 8y-roc(4irstar,< secondar,) 8y-roc 4irstar,< secondar, @otice t+at t+e parent+eses are omitted in t+e call 6+en t+e Call statement isn9t used5

28

/0 Script 0ui%t in ;unctions


T*pes o( ;unctions o o o o o o o o o Con7ersions (2 ) Dates"Times (1%) /ormattin, Strin,s (4) Input"Output (3) 8at+ (%) 8iscellaneous (3) 0oundin, ( ) Strin,s (3)) Variants ($)

I#portant ;unctions 1) A&s ;unction 0eturns t+e absolute 7alue o4 a number5 Dim num numGabs(. )533) ms,bo( num 2) Arra* ;unction 0eturns a 7ariant containin, an 3rray Dim 3 3G3rray(B+yderabadB<Bc+ennaiB<BmumbaiB) ms,bo( 3()) 0eDim 3( ) 3(4)GBnelloreB ms,bo( 3(4) !) Asc ;unction 0eturns t+e 3@SI c+aracter code correspondin, to t+e 4irst letter in a strin,5 Dim num numG3sc(B3B) ms,bo( num N It returns t+e 7alue ! N $) Chr ;unction 0eturns t+e c+aracter associated 6it+ t+e speci4ied 3@SI c+aracter code5 Dim c+ar C+arGC+r(! ) ms,bo( c+ar

29

N It returns 3 N 4) CInt ;unction 0eturns an e(pression t+at +as been con7erted to a /ariant o4 subtype Integer5 Dim num numG12354 myIntGCInt(num) ms,bo( 8yInt 6) 1ate ;unction 0eturns t+e Current System Date5 Dim mydate mydateGDate ms,bo( mydate 7) 1a* ;unction '(1) Dim myday mydayGDay(B1#<December<2))%B) ms,bo( myday Dim myday mydateGdate mydayGDay(8ydate) ms,bo( myday

'(2)

8) 1ate1i(( ;unction 0eturns t+e number o4 inter7als bet6een t6o dates5 1i# #*da* #*dateGK'2@17@2''CK +G1atedi(((LdL?#*date? ow) #sg&o+ + C) Hour ;unction 0eturns a 6+ole number bet6een ) and 23< inclusi7e< representin, t+e +our o4 t+e day5 Dim mytime< 8y+our mytimeG@o6 my+ourG+our (mytime) ms,bo( my+our 1') Moin ;unction 0eturns a strin, created by ?oinin, a number o4 substrin,s contained in an array5 Dim mystrin,< myarray(3) myarray())GBC+andra B myarray(1)GB8o+an B myarray(2)GB0eddyB mystrin,GCoin(8y3rray) ms,bo( mystrin,

30

11) "va% ;unction '7aluates an e(pression and returns t+e result5 12) Ti#e ;unction 0eturns a /ariant o4 subtype 1ate indicatin, t+e current system time5 Dim mytime mytimeGTime ms,bo( mytime 1!) /arT*pe ;unction 0eturns a 7alue indicatin, t+e subtype o4 a 7ariable5 Dim 8yC+ec> 8yC+ec> G VarType(3))) 8s,bo( 8yc+ec> 9 0eturns 25 9 0eturns #5

8yC+ec> G VarType(T1)"1%"!2T) 8s,bo( 8yc+ec> 8yC+ec> G VarType(BVBScriptB) 8s,bo( 8yc+ec> 1$) 5e(t ;unction

9 0eturns $5

Dim 8yStrin,< *e4tStrin, 8yStrin, G BVBSCriptB *e4tStrin, G *e4t(8yStrin,< 3) 9 *e4tStrin, contains BVBSB5 1$) 3ight ;unction Dim 3nyStrin,< 8yStr 3nyStrin, G B;ello :orldB 9 De4ine strin,5 8yStr G 0i,+t(3nyStrin,< 1) 9 0eturns BdB5 8yStr G 0i,+t(3nyStrin,< !) 9 0eturns B :orldB5 8yStr G 0i,+t(3nyStrin,< 2)) 9 0eturns B;ello :orldB5 14) 5en ;unction 0eturns t+e number o4 c+aracters in a strin, or t+e number o4 bytes re1uired to store a 7ariable5 '( 1)F Dim 8ystrin, mystrin,G*en(B&5C50eddyB) ms,bo( mystrin, '( 2)F Dim 8ystrin, 8ystrin,GInputbo((B'nter a ValueB) 8ystrin,G*en(8ystrin,)

31

8s,bo( 8ystrin, 16) <id ;unction 0eturns a speci4ied number o4 c+aracters 4rom a strin,5 Dim 8yVar 8yVar G 8id(BVB Script is 4unSB< 4< !) 8s,bo( 8yVar N It 0eturns XScriptY N 17) Ti#er ;unction 0eturns t+e number o4 seconds t+at +a7e elapsed since 12F)) 38 (midni,+t)5 /unction myTime(@) Dim StartTime< 'ndTime StartTime G Timer /or I G 1 To @ @e(t 'ndTime G Timer myTimeG 'ndTime . StartTime ms,bo( myTime 'nd /unction Call myTime(2)))) 17) is u#eric ;unction Dim 8yVar< 8yC+ec> 8yVar G 3 8yC+ec> G Is@umeric(8yVar) ms,bo( 8yC+ec> 8yVar G B4 %5% B 8yC+ec> G Is@umeric(8yVar) ms,bo( 8yC+ec> 8yVar G B4 ;elpB 8yC+ec> G Is@umeric(8yVar) ms,bo( 8yC+ec> N It 0eturns True"/alse li>e 0esult N 18) Input&o+ ;unction Displays a prompt in a dialo, bo(< 6aits 4or t+e user to input te(t or clic> a button< and returns t+e contents o4 t+e te(t bo(5 Dim Input Input G InputBo((B'nter your nameB) 8s,Bo( (BLou enteredF B P Input) 1C) <sg&o+ ;unction Displays a messa,e in a dialo, bo(< 6aits 4or t+e user to clic> a button< and returns a 7alue indicatin, 6+ic+ button t+e user clic>ed5

32

Dim 8yVar 8yVar G 8s,Bo( (B;ello :orldSB< ! < B8s,Bo( '(ampleB)

/0Script s*nta+ ru%es and guide%ines


21.1 Case@sensitivit*) By de4ault< VBScript is not case sensiti7e and does not di44erentiate bet6een upper case and lo6er.case spellin, o4 6ords< 4or e(ample< in 7ariables< ob?ect and met+od names< or constants5 /or e(ample< t+e t6o statements belo6 are identical in VBScriptF Bro6ser(B8ercuryB)5-a,e(B/ind a /li,+tFB)5:eb*ist(BtoDayB)5Select B31B bro6ser(BmercuryB)5pa,e(B4ind a 4li,+tFB)56eblist(BtodayB)5select B31B 21.2 Te+t strings) :+en 6e enter a 7alue as a te(t strin,< 6e must add 1uotation mar>s be4ore and a4ter t+e strin,5 /or e(ample< in t+e abo7e se,ment o4 script< t+e names o4 t+e :eb site< :eb pa,e< and edit bo( are all te(t strin,s surrounded by 1uotation mar>s5 @ote t+at t+e 7alue 31 is also surrounded by 1uotation mar>s< because it is a te(t strin, t+at represents a number and not a numeric 7alue5 In t+e 4ollo6in, e(ample< only t+e property name (4irst ar,ument) is a te(t strin, and is in 1uotation mar>s5 T+e second ar,ument (t+e 7alue o4 t+e property) is a 7ariable and t+ere4ore does not +a7e 1uotation mar>s5 T+e t+ird ar,ument (speci4yin, t+e timeout) is a numeric 7alue< 6+ic+ also does not need 1uotation mar>s5 Bro6ser(B8ercuryB)5-a,e(B/ind a /li,+tFB)5:ait-roperty(Bitems countB< TotalZItems< 2)))) 21.! /aria&%es) :e can speci4y 7ariables to store strin,s< inte,ers< arrays and ob?ects5 Hsin, 7ariables +elps to ma>e our script more readable and 4le(ible 21.$ Parentheses) To ac+ie7e t+e desired result and to a7oid errors< it is important t+at 6e use parent+eses () correctly in our statements5 21.4 Indentation) :e can indent or outdent our script to re4lect t+e lo,ical structure and nestin, o4 t+e statements5 21.6 Co##ents) :e can add comments to our statements usin, an apostrop+e (9)< eit+er at t+e be,innin, o4 a separate line< or at t+e end o4 a statement5 It is recommended t+at

33

6e add comments 6+ere7er possible< to ma>e our scripts easier to understand and maintain5 21.7 Spaces) :e can add e(tra blan> spaces to our script to impro7e clarity5 T+ese spaces are i,nored by VBScript5

"rrors
:e +a7e t6o types 'rrors in VB ScriptE t+ey are VBScript 0un.time 'rrors and VBScript Synta( 'rrors 1!.1 /0Script 3un@ti#e "rrors VBScript run.time errors are errors t+at result 6+en our VBScript script attempts to per4orm an action t+at t+e system cannot e(ecute5 VBScript run.time errors occur 6+ile our script is bein, e(ecutedE 6+en 7ariable e(pressions are bein, e7aluated< and memory is bein, dynamic allocated5 1!.2 /0Script S*nta+ "rrors VBScript synta( errors are errors t+at result 6+en t+e structure o4 one o4 our VBScript statements 7iolates one or more o4 t+e ,rammatical rules o4 t+e VBScript scriptin, lan,ua,e5 VBScript synta( errors occur durin, t+e pro,ram compilation sta,e< be4ore t+e pro,ram +as be,un to be e(ecuted5

34

35

;i%e S*ste# 2perations


I) Wor.ing with 1rives and ;o%ders
a) Creating a ;o%der Option '(plicit Dim ob?/SO< ob?/older< strDirectory strDirectory G BDFOlo,sB Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set ob?/older G ob?/SO5Create/older(strDirectory) &) 1e%eting a ;o%der Set o/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) o/SO5Delete/older(B'FO/SOB) c) Cop*ing ;o%ders Set o/SOGcreateob?ect(BScriptin,5/ilesystemob?ectB) o/SO5Copy/older B'FO,cr!B< BCFO?7rB< True d) Chec.ing weather the (o%der avai%a&%e or not? i( not creating the (o%der Option '(plicit Dim ob?/SO< ob?/older< strDirectory strDirectory G BDFOlo,sB Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) I4 ob?/SO5/older'(ists(strDirectory) T+en Set ob?/older G ob?/SO5&et/older(strDirectory) ms,bo( strDirectory P B already created B else Set ob?/older G ob?/SO5Create/older(strDirectory) end i4 e) 3eturning a co%%ection o( 1is. 1rives Set o/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set colDri7es G o/SO5Dri7es /or 'ac+ oDri7e in colDri7es 8s,Bo( BDri7e letterF B P oDri7e5Dri7e*etter @e(t () Jetting avai%a&%e space on a 1is. 1rive Set o/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set oDri7e G o/SO5&etDri7e(BCFB) 8s,Bo( B37ailable spaceF B P oDri7e537ailableSpace

36

II) Wor.ing with ;%at ;i%es


a) Creating a ;%at ;i%e Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set ob?/ile G ob?/SO5CreateTe(t/ile(B'FOScript*o,5t(tB) &) Chec.ing weather the ;i%e is avai%a&%e or not? i( not creating the ;i%e strDirectoryGB'FOB str/ileGBScriptin,5t(tB Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) I4 ob?/SO5/ile'(ists(strDirectory P str/ile) T+en Set ob?/older G ob?/SO5&et/older(strDirectory) 'lse Set ob?/ile G ob?/SO5CreateTe(t/ile(B'FOScript*o,5t(tB) 'nd i4 c) 3eading 1ata character &* character (ro# a ;%at ;i%e Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set ob?/ile G ob?/SO5OpenTe(t/ile(B'FO,cr5t(tB< 1) Do Hntil ob?/ile53t'ndO4Stream strC+aracters G ob?/ile50ead(1) ms,bo( strC+aracters *oop d) 3eading 1ata %ine &* %ine (ro# a ;%at ;i%e Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set ob?/ile G ob?/SO5OpenTe(t/ile(B'FO,cr5t(tB< 1) Do Hntil ob?/ile53t'ndO4Stream strC+aracters G ob?/ile50eadline ms,bo( strC+aracters *oop e) 3eading data (ro# a (%at (i%e and using in data driven testing Dim 4so<my4ile Set 4soGcreateob?ect(Bscriptin,54ilesystemob?ectB) Set my4ileG 4so5opente(t4ile (B/FO,cr5t(tB<1) my4ile5s>ipline :+ile my4ile5atendo4line QR True (Gmy4ile5readline sGsplit ((< B<B) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB<BB<BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappOB<BopenB

37

Dialo,(B*o,inB)53cti7ate Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set s()) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure s(1) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> :indo6(B/li,+t 0eser7ationB)5Close :end () Writing data to a te+t (i%e Dim Stu44< my/SO< :riteStu44< dateStamp dateStamp G Date() Stu44 G BI am -reparin, t+is scriptF B PdateStamp Set my/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set :riteStu44 G my/SO5OpenTe(t/ile(BeFO,cr5t(tB< $< True) :riteStu445:rite*ine(Stu44) :riteStu445Close S'T :riteStu44 G @OT;I@& S'T my/SO G @OT;I@& g) 1e%ete a te+t (i%e Set ob?/SOGcreateob?ect(BScriptin,54ilesystemob?ectB) Set t(t/ilepat+ G ob?/SO5&et/ile(B'FO,cr5t(tB) t(t/ilepat+5Delete() h) Chec.ing weather the ;i%e is avai%a&%e or not? i( avai%a&%e de%ete the ;i%e strDirectoryGB'FOB str/ileGB,cr5t(tB Set ob?/SO G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) I4 ob?/SO5/ile'(ists(strDirectory P str/ile) T+en Set ob?/ile G ob?/SO5&et4ile(strDirectory P str/ile) ob?/ile5delete () 'nd i4 i) Co#paring two te+t (i%es Dim 41< 42 41GBeFO,cr15t(tB 42GBeFO,cr25t(tB -ublic /unction Compare/iles (/ile-at+1< /ile-at+2) Dim /S< /ile1< /ile2 Set /S G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) I4 /S5&et/ile(/ile-at+1)5SiIe QR /S5&et/ile(/ile-at+2)5SiIe T+en Compare/iles G True '(it /unction 'nd I4 Set /ile1 G /S5&et/ile(/ile-at+1)5Open3sTe(tStream(1< )) Set /ile2 G /S5&et/ile(/ile-at+2)5Open3sTe(tStream(1< ))

38

Compare/iles G /alse Do :+ile /ile153t'ndO4Stream G /alse Str1 G /ile150ead Str2 G /ile250ead Compare/iles G StrComp(Str1< Str2< )) I4 Compare/iles QR ) T+en Compare/iles G True '(it Do 'nd I4 *oop /ile15Close() /ile25Close() 'nd /unction Call Compare4iles(41<42) I4 Compare/iles(41< 42) G /alse T+en 8s,Bo( B/iles are identical5B 'lse 8s,Bo( B/iles are di44erent5B 'nd I4 A) Counting the nu#&er o( ti#es a word appears in a (i%e s/ile@ameGB'FO,cr5t(tB sStrin,GB,creddyB Const /O0Z0'3DI@& G 1 Dim o/so< oT(t/ile< s0eadT(t< o0e,'(< o8atc+es Set o/so G CreateOb?ect(BScriptin,5/ileSystemOb?ectB) Set oT(t/ile G o/so5OpenTe(t/ile(s/ile@ame< /O0Z0'3DI@&) s0eadT(t G oT(t/ile50ead3ll Set o0e,'( G @e6 0e,'(p o0e,'(5-attern G sStrin, o0e,'(5I,noreCase G bI,noreCase o0e,'(5&lobal G True Set o8atc+es G o0e,'(5'(ecute(s0eadT(t) 8atc+es/ound G o8atc+es5Count Set oT(t/ile G @ot+in, F Set o/so G @ot+in, F Set o0e,'( G @ot+in, ms,bo( 8atc+es/ound

III) Wor.ing with Word 1ocs


a) Create a word docu#ent and enter so#e data : save Dim ob?:D Set ob?:D G CreateOb?ect(B:ord53pplicationB) ob?:D5Documents53dd

39

ob?:D5Selection5TypeTe(t BT+is is some te(t5B P C+r(13) P BT+is is some more te(tB ob?:D53cti7eDocument5Sa7e3s BeFO,creddy5docB ob?:D52uit

I/) Wor.ing with "+ce% Sheets


a) Create an e+ce% sheet and enter a va%ue into (irst ce%% Dim ob?e(cel Set ob?'(cel G createob?ect(B'(cel5applicationB) ob?e(cel5Visible G True ob?e(cel5:or>boo>s5add ob?e(cel5Cells(1< 1)5Value G BTestin,B ob?e(cel53cti7e:or>boo>5Sa7e3s(B4FO,creddy15(lsB) ob?e(cel52uit &) Co#pare two e+ce% (i%es Set ob?'(cel G CreateOb?ect(B'(cel53pplicationB) ob?'(cel5Visible G True Set ob?:or>boo>1G ob?'(cel5:or>boo>s5Open(B'FO,cr15(lsB) Set ob?:or>boo>2G ob?'(cel5:or>boo>s5Open(B'FO,cr25(lsB) Set ob?:or>s+eet1G ob?:or>boo>15:or>s+eets(1) Set ob?:or>s+eet2G ob?:or>boo>25:or>s+eets(1) /or 'ac+ cell In ob?:or>s+eet15Hsed0an,e I4 cell5Value QR ob?:or>s+eet250an,e(cell53ddress)5Value T+en ms,bo( B7alue is di44erentB 'lse ms,bo( B7alue is sameB 'nd I4 @e(t ob?:or>boo>15close ob?:or>boo>25close ob?'(cel51uit set ob?'(celGnot+in,

40

Test 3eNuire#ents
1) /eri(* 5ogin 0oundar* (C+ec> all t+e boundary conditions o4 t+e *o,in 6indo65 C+ec>s to see i4 t+e correct messa,e appears in t+e error 6indo6 (/li,+t 0eser7ation 8essa,e) 2) /eri(* Cance% 2peration (in *o,in Dialo, bo(< i4 user selects cancel button< be4ore enter any data a4ter enter data dialo, bo( s+ould be disappeared5) !) /eri(* Addition? Su&traction? <u%tip%ication and 1ivision 2perations in Ca%cu%ator App%ication. 4) /eri(* state o( -pdate 2rder 0utton? &e(ore open an 2rder and a(ter open an 2rder (in /li,+t 0eser7ation be4ore openin, an order Hpdate Order button s+ould be disabled a4ter openin, an order enabled5) ) Price Consistenc*? In ;%ight 3eservation (In /li,+t 0eser7ation< /irst class priceG3N'conomy class price and Business class priceG2N'conomy class price) !) /eri(* Tota%? In ;%ight 3eservation (In /li,+t 0eser7ation< Total G Tic>ets N -rice)

41

#) /eri(* ;%ight ;ro# : ;%ight To Co#&o 0o+es (In /li,+t reser7ation< select an item 4rom /ly /romF combo bo( and 7eri4y 6eat+er t+at item a7ailable or not in /ly ToF combo bo(< li>e t+is select all items one by one in /ly /rom and 7eri4y 6eat+er selected items a7ailable or not in /ly To5) $) /eri(* 2rder o "ntr* in ;%ight 3eservation. (In Open Order dialo, bo(< Order @o ob?ect accepts numeric 7alues only5) C) Jet Test 1ata (ro# a ;%at (i%e and use in 1ata 1riven Testing (through Scripting) 1') Jet Test 1ata ;ro# a 1ata&ase and use in 1ata 1riven Testing (through Scripting) 11) Count? how #an* %in.s avai%a&%e in <ercur* Tours Ho#e Page>

12) Count how #an* 0uttons and "dit &o+es avai%a&%e in ;%ight 3eservation window> 1!) /eri(* search options in 2pen 2rder 1ia%og &o+ (34ter selectin, open order< 3 searc+ options s+ould be enabled and not c+ec>ed< 34ter selectin, Order @o option< ot+er options s+ould be disabled< 34ter selectin, Customer @ame< /li,+t date option enabled and Order @o disabled 34ter selectin, /li,+t date option< Customer @ame enabled and Order @o disabled ) 1$) In 5ogin 1ia%og &o+? /eri(* He%p #essage (T+e messa,e is XT+e pass6ord is 98'0CH0L9) 14) Count a%% opened 0rowsers on des.top and c%ose a%%> 16) Create an "+ce% (i%e? enter so#e data and save the (i%e through /0 scripting>

So%utions)
1) /eri(* 5ogin 0oundar* (C+ec> all t+e boundary conditions o4 t+e *o,in dialo, bo(5 C+ec>s to see i4 t+e correct messa,e appears in t+e error 6indo6 (/li,+t 0eser7ation 8essa,e) 1) 3pplicationDir G 'n7ironment(B-roductDirB)

42

2) 3pplication-at+ G BOsamplesO4li,+tOappO4li,+t4a5e(eB 3) I4 :indo6(B/li,+t 0eser7ationB)5'(ist(2) T+en 4) :indo6(B/li,+t 0eser7ationB)5Close ) SystemHtil50un 3pplicationDir P 3pplication-at+ !) 'lsei4 @ot Dialo,(B*o,inB)5'(ist(1) T+en #) SystemHtil50un 3pplicationDir P 3pplication-at+ $) 'nd I4 %) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Datatable5Value (B3,ent@ameB<dt&lobalS+eet) 1))Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5Set Datatable5Value (B-ass6ordB<dt&lobalS+eet) 11)Dialo,(B*o,inB)5:inButton(BO[B)5Clic> 12)I4 Dialo,(B*o,inB)5Dialo,(B/li,+t 0eser7ationsB)5'(ist(1) and Datatable5Value (BStatusB<dt&lobalS+eet)GB/ailB T+en 13)Dialo,(B*o,inB)5Dialo,(B/li,+t 0eser7ationsB)5Static(B3,ent name must be atB)5C+ec> C+ec>-oint(B3,ent name must be at least 4 c+aracters lon,5B) 14)Dialo,(B*o,inB)5Dialo,(B/li,+t 0eser7ationsB)5:inButton(BO[B)5Clic> 1 )'lsei4 :indo6(B/li,+t 0eser7ationB)5'(ist(1)) and Datatable5Value (BStatusB<dt&lobalS+eet)GB-assB T+en 1!)0eporter50eport'7ent -3SS<B*o,inF B<BSucceededB 1#)'lse 1$)0eporter50eport'7ent /ail<B*o,inF B<BCombination TB P Datatable5&etCurrent0o6 P B 6as not accordin, to '(cel 4ileB 1%)'nd I4 2) /eri(* Cance% 2peration (in *o,in Dialo, bo(< i4 user selects cancel button< be4ore enter any data a4ter enter data dialo, bo( s+ould be disappeared5) 1) In7o>eapplication BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 2) Dialo,(B*o,inB)53cti7ate 3) Dialo,(B*o,inB)5:inButton(BCancelB)5Clic> 4) I4 Dialo,(B*o,inB)5'(ist (2) GTrue T+en ) 0eporter50eport'7ent 1<BsdB<B/ailB !) 'lse #) 0eporter50eport'7ent )<BsdB<B-assB

43

$) In7o>eapplication BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB %) 'nd I4 1))Dialo,(B*o,inB)53cti7ate 11)Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Basd4B 12)Dialo,(B*o,inB)5:inButton(BCancelB)5Clic> 13)I4 Dialo,(B*o,inB)5'(ist (2) GTrue T+en 14)0eporter50eport'7ent 1<BsdB<B/ailB 1 )'lse 1!)0eporter50eport'7ent )<BsdB<B-assB 1#)In7o>eapplication BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 1$)'nd I4 1%)Dialo,(B*o,inB)53cti7ate 2))Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Basd4B 21)Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4a%%3a44 dcbd )!c$4 1b2#4d2da)#b3$44 31B 22)Dialo,(B*o,inB)5:inButton(BCancelB)5Clic> 23)I4 Dialo,(B*o,inB)5'(ist (2)GTrue T+en 24)0eporter50eport'7ent 1<BsdB<B/ailB 2 )'lse 2!)0eporter50eport'7ent )<BsdB<B-assB 2#)In7o>eapplication BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 2$)'nd I4 2%)Dialo,(B*o,inB)53cti7ate 3))Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Basd4B 31)Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4a%%3a44 dcbd )!c$4 1b2#4d2da)#b3$44 31B 32)Dialo,(B*o,inB)5:inButton(BO[B)5Clic> !) /eri(* Addition? Su&traction? <u%tip%ication and 1ivision 2perations in Ca%cu%ator App%ication. 1) Dim a0es<s0es<d0es<m0es 2) Vb:indo6(BVb:indo6B)53cti7ate 3) Vb:indo6(BVb:indo6B)5Vb'dit(BVb'ditB)5Set B1)B 4) Vb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ2B)5Set B2)B

44

) 71GVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditB)5&et0O-roperty (Bte(tB) !) 72GVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ2B)5&et0O-roperty (Bte(tB) #) Vb:indo6(BVb:indo6B)5VbButton(B3DDB)5Clic> $) a0esGVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ3B)5&etVisibleTe(t %) Vb:indo6(BVb:indo6B)5VbButton(BSHBB)5Clic> 1))s0esGVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ3B)5&etVisibleTe(t 11)Vb:indo6(BVb:indo6B)5VbButton(B8H*B)5Clic> 12)m0esGVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ3B)5&etVisibleTe(t 13)Vb:indo6(BVb:indo6B)5VbButton(BDIVB)5Clic> 14)d0esGVb:indo6(BVb:indo6B)5Vb'dit(BVb'ditZ3B)5&etVisibleTe(t 1 )71Gcdbl(71) 1!)72Gcdbl(72) 1#)a0esGcdbl (a0es) 1$)s0esGcdbl (s0es) 1%)m0esGcdbl (m0es) 2))d0esGcdbl (d0es) 21)I4 a0esG71A72 T+en 22)0eporter50eport'7ent )<B0esB<B3ddition -assedB 23)else 24)0eporter50eport'7ent 1<B0esB<B3ddition /ailedB 2 )'nd I4 2!)I4 s0esG71.72 T+en 2#)0eporter50eport'7ent )<B0esB<BSubtraction -assedB 2$)else 2%)0eporter50eport'7ent 1<B0esB<BSubtraction /ailedB 3))'nd I4 31)I4 m0esG71N72 T+en 32)0eporter50eport'7ent )<B0esB<B8ultiplecation -assedB 33)else 34)0eporter50eport'7ent 1<B0esB<B8ultiplecation /ailedB 3 )'nd I4 3!)I4 d0esG71"72 T+en 3#)0eporter50eport'7ent )<B0esB<BDi7ision -assedB 3$)else 3%)0eporter50eport'7ent 1<B0esB<BDi7ision /ailedB

45

4))'nd I4 $) /eri(* state o( -pdate 2rder 0utton? &e(ore open an 2rder and a(ter open an 2rder (in /li,+t 0eser7ation be4ore openin, an order Hpdate Order button s+ould be disabled a4ter openin, an order enabled5) 1) Option e(plicit 2) Dim bo<ao 3) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en 4) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB ) Dialo,(B*o,inB)53cti7ate !) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set B&creddyB #) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4aa$bce%%$441a1 ea1$#a2da b1$c 4 abb)1c4B $) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> %) 'nd I4 1)):indo6(B/li,+t 0eser7ationB)53cti7ate 11)boG:indo6(B/li,+t 0eser7ationB)5:inButton(BHpdate OrderB)5&et0O-roperty (B'nabledB) 12):indo6(B/li,+t 0eser7ationB)5:inButton(BButtonB)5Clic> 13):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO@B 14):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5Set B1B 1 ):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inButton(BO[B)5Clic> 1!)aoG:indo6(B/li,+t 0eser7ationB)5:inButton(BHpdate OrderB)5&et0O-roperty (B'nabledB) 1#)I4 boG/alse T+en 1$)0eporter50eport'7ent )<B0esB<BHpdate Order Button DisabledB 1%)else 2))0eporter50eport'7ent 1<B0esB<BHpdate Order Button 'nabledB 21)'nd I4 22)I4 aoGTrue T+en 23)0eporter50eport'7ent )<B0esB<BHpdate Order Button 'nabledB 24)else 2 )0eporter50eport'7ent 1<B0esB<BHpdate Order Button DisabledB 2!)'nd I4

46

4) Price Consistenc*? In ;%ight 3eservation (In /li,+t 0eser7ation< /irst class priceG3N'conomy class price and Business class priceG2N'conomy class price) 1) Option e(plicit 2) Dim n<4<b<e 3) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en 4) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB ) Dialo,(B*o,inB)53cti7ate !) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Basd4B #) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4aa$b#b#c $23!$)c4cb24d3)#14c%bb4)d441ebB $) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> %) 'nd I4 1))/or nG 1 to 1) step 1 11):indo6(B/li,+t 0eser7ationB)53cti7ate 12):indo6(B/li,+t 0eser7ationB)5:inButton(BButtonB)5Clic> 13):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO@B 14):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5Set n 1 ):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inButton(BO[B)5Clic> 1!):indo6(B/li,+t 0eser7ationB)5:in0adioButton(B/irstB)5Set 1#)4G:indo6(B/li,+t 0eser7ationB)5:in'dit(B-riceFB)5&etVisibleTe(t 1$):indo6(B/li,+t 0eser7ationB)5:in0adioButton(BBusinessB)5Set 1%)bG:indo6(B/li,+t 0eser7ationB)5:in'dit(B-riceFB)5&etVisibleTe(t 2)):indo6(B/li,+t 0eser7ationB)5:in0adioButton(B'conomyB)5Set 21)eG:indo6(B/li,+t 0eser7ationB)5:in'dit(B-riceFB)5&etVisibleTe(t 22)4Gcdbl(mid(4<2<len (4.1))) 23)bGcdbl(mid(b<2<len (b.1))) 24)eGcdbl(mid(e<2<len (e.1))) 2 )I4 4G3Ne and bG2Ne T+en 2!)0eporter50eport'7ent )<B0esB<B-ricy Consistancy is t+ereB 2#)else 2$)0eporter50eport'7ent 1<B0esB<B-ricy Consistancy is @OT t+ereB 2%)'nd I4 3)):indo6(B/li,+t 0eser7ationB)5:inButton(BButtonZ2B)5Clic>

47

31):indo6(B/li,+t 0eser7ationB)5Dialo,(B/li,+t 0eser7ationsB)5:inButton(B@oB)5Clic> 32)@e(t 6) /eri(* Tota%? In ;%ight 3eservation (In /li,+t 0eser7ation< Total G Tic>ets N -rice) 1) Option '(plicit 2) Dim t<p<tot<n 3) /or nG 1 to 1) step 1 4) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en ) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB<BB<BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappOB<BopenB !) Dialo,(B*o,inB)53cti7ate #) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set B&creddyB $) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4aa$%2d!2c 2%41c232%$1# ad#$c $443da$e34B %) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> 1))'nd I4 11):indo6(B/li,+t 0eser7ationB)53cti7ate 12):indo6(B/li,+t 0eser7ationB)5:inButton(BButtonB)5Clic> 13):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO@B 14):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5Set n 1 ):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inButton(BO[B)5Clic> 1!)tG:indo6(B/li,+t 0eser7ationB)5:in'dit(BTic>etsFB)5&etVisibleTe(t 1#)pG:indo6(B/li,+t 0eser7ationB)5:in'dit(B-riceFB)5&etVisibleTe(t 1$)totG:indo6(B/li,+t 0eser7ationB)5:in'dit(BTotalFB)5&etVisibleTe(t 1%)tGcdbl (t) 2))pGCdbl(mid(p<2<len (p.1))) 21)totGCdbl(mid(tot<2<len (tot.1))) 22)I4 totGtNp T+en 23)0eporter50eport'7ent )<B0esB<BCalculation -assedB 24)else

48

2 )0eporter50eport'7ent 1<B0esB<BCalculation /ailedB 2!)'nd I4 2#)@e(t 7) /eri(* ;%ight ;ro# : ;%ight To Co#&o 0o+es (In /li,+t reser7ation< select an item 4rom /ly /romF combo bo( and 7eri4y 6eat+er t+at item a7ailable or not in /ly ToF combo bo(< li>e t+is select all items one by one in /ly /rom and 7eri4y 6eat+er selected items a7ailable or not in /ly To5) 1) Option e(plicit 2) Dim 1tp<4li,+tZapp<4<t<i<?<(<y 3) I4 @ot :indo6(Bte(tFG/li,+t 0eser7ationB)5'(ist (#)G True T+en 4) 2T-G'n7ironment(B-roductDirB) ) /li,+tZappGBOsamplesO4li,+tOappO4li,+t4a5e(eB !) SystemHtil50un 2T- P /li,+tZapp #) Dialo,(Bte(tFG*o,inB)53cti7ate $) Dialo,(Bte(tFG*o,inB)5:in'dit(Battac+ed te(tFG3,ent @ameFB)5Set Basd4B %) Dialo,(Bte(tFG*o,inB)5:in'dit(Battac+ed te(tFG-ass6ordFB)5SetSecure B4aa ed3da4!$)e#a# %bee1c 41%3%d3a 4a b! B 1))Dialo,(Bte(tFG*o,inB)5:inButton(Bte(tFGO[B)5Clic> 11)'nd I4 12):indo6(Bte(tFG/li,+t 0eser7ationB)53cti7ate 13):indo6(Bte(tFG/li,+t 0eser7ationB)5:inButton(B6indo6 idFG!B)5Clic> 14):indo6(Bte(tFG/li,+t 0eser7ationB)53cti7eD(Bac(ZnameFG8as>'dBo(B<B6indo6 idFG)B)5Type B)%)%1)B 1 )4G:indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly /romFB)5&etItemsCount 1!)/or iG ) to 4.1 step 1 1#):indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly /romFB)5Select (i) 1$)(G:indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly /romFB)5&et0O-roperty (Bte(tB) 1%)tG:indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly ToFB<B(FG244B<ByFG14#B)5&etItemsCount 2))/or ?G ) to t.1 step 1 21):indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly ToFB<B(FG244B<ByFG14#B)5Select (?) 22)yG:indo6(Bte(tFG/li,+t 0eser7ationB)5:inComboBo((Battac+ed te(tFG/ly ToFB<B(FG244B<ByFG14#B)5&et0O-roperty (Bte(tB)

49

23)I4 ( QR y T+en 24)0eporter50eport'7ent )<B0esB<BTest -assedB 2 )'lse 2!)0eporter50eport'7ent 1<B0esB<BTest /ailedB 2#)'nd I4 2$)@e(t 2%)@e(t 8) /eri(* 2rder o "ntr* in ;%ight 3eservation. (In Open Order dialo, bo(< Order @o ob?ect accepts numeric 7alues only5) 1) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en 2) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 3) Dialo,(B*o,inB)53cti7ate 4) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set Basd4B ) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure B4aa%ccae3bb))%!2b4#44#4b)ce3 24c1d$$cb43B !) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> #) 'nd I4 $) :indo6(B/li,+t 0eser7ationB)53cti7ate %) :indo6(B/li,+t 0eser7ationB)5:inButton(BButtonB)5Clic> 1)):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO@B 11):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5Set BaB 12)ordG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5&etVisibleTe(t 13)I4 ordG BaB T+en 14)0eporter50eport'7ent 1<B0esB<BOrder @o Ob?ect is ta>in, in7alid dataB 1 )else 1!):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:in'dit(B'ditB)5Set B1B 1#):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inButton(BO[B)5Clic> 1$)'nd I4 C) Jet Test 1ata (ro# a ;%at (i%e and use in 1ata 1riven Testing (through Scripting) 1) Dim 4so<my4ile 2) Set 4soGcreateob?ect(Bscriptin,54ilesystemob?ectB) 3) Set my4ileG 4so5opente(t4ile (B/FO,cr5t(tB<1)

50

4) my4ile5s>ipline ) :+ile my4ile5atendo4line QR True !) (Gmy4ile5readline #) sGsplit ((< B<B) $) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB %) Dialo,(B*o,inB)53cti7ate 1))Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set s()) 11)Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5SetSecure s(1) 12)Dialo,(B*o,inB)5:inButton(BO[B)5Clic> 13):indo6(B/li,+t 0eser7ationB)5Close 14):end 1') Jet Test 1ata ;ro# a 1ata&ase and use in 1ata 1riven Testing (through Scripting) 1) Dim con<rs 2) Set conGcreateob?ect(B3dodb5connectionB) 3) Set rsGcreateob?ect(B3dodb5recordsetB) 4) con5pro7iderG(Bmicroso4t5?et5oledb545)B) ) con5open BCFODocuments and Settin,sO3dministratorO8y DocumentsO&cr5mdbB !) rs5open BSelect N /rom *o,inB<con #) :+ile rs5eo4 QRTrue $) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB %) Dialo,(B*o,inB)53cti7ate 1))Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set rs54ields (B3,entB) 11)Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5Set rs54ields (B-ass6ordB) 12)Dialo,(B*o,inB)5:inButton(BO[B)5Clic> 13):indo6(B/li,+t 0eser7ationB)5Close 14)rs5mo7ene(t 1 ):end 11) Count? how #an* %in.s avai%a&%e in <ercur* Tours Ho#e Page. 1) Set oDesc G Description5Create() 2) oDesc(BmicclassB)5Value G B*in>B

51

3) Set *ists G Bro6ser(B:elcomeF 8ercuryB)5-a,e(B:elcomeF 8ercuryB)5C+ildOb?ects (oDesc) 4) @umberO4*in>s G *ists5Count() ) 0eporter50eport'7ent 2<B0esB<B@umber o4 *in>s areF BP@umberO4*in>s 12) Count? how #an* 0uttons and "dit &o+es avai%a&%e in ;%ight 3eservation #ain window. 1) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en 2) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 3) Dialo,(B*o,inB)53cti7ate 4) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set B&creddyB ) Dialo,(B*o,inB)5:in'dit(B-ass6ordFB)5Set BmercuryB !) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> #) 'nd I4 $) Set oDesc G Description5Create() %) oDesc(BmicclassB)5Value G B:inButtonB 1))Set Buttons G :indo6(Bte(tFG/li,+t 0eser7ationB)5C+ildOb?ects (oDesc) 11)@umZButtons G Buttons5Count() 12)Set oDesc1GDescription5Create() 13)oDesc1(BmicclassB)5ValueGB:in'ditB 14)Set 'ditbo(esG:indo6(Bte(tFG/li,+t 0eser7ationB)5C+ildOb?ects (oDesc1) 1 )@umZ'ditbo(esG editbo(es5count () 1!)sumG @umZButtonsA@umZ'ditbo(es 1#)0eporter50eport'7ent 2< B0esB<BTotal ButtonsF BP @umZButtons PBTotal 'dit bo(esF BP @umZ'ditbo(es 1!) /eri(* search options in 2pen 2rder 1ia%og &o+ (34ter selectin, open order< 3 searc+ options s+ould be enabled and not c+ec>ed< 34ter selectin, Order @o option< ot+er options s+ould be disabled< 34ter selectin, Customer @ame< /li,+t date option enabled and Order @o disabled 34ter selectin, /li,+t date option< Customer @ame enabled and Order @o disabled ) 1) I4 @ot 6indo6(B/li,+t 0eser7ationB)5'(ist (2) T+en 2) SystemHtil50un BCFO-ro,ram /ilesO8ercury Interacti7eO2uic>Test -ro4essionalOsamplesO4li,+tOappO4li,+t4a5e(eB 3) Dialo,(B*o,inB)53cti7ate

52

4) Dialo,(B*o,inB)5:in'dit(B3,ent @ameFB)5Set B&creddyB 4) 1ia%og(L5oginL).Win"dit(LPassword)L).SetSecure L$aaCed24&c'e&de66ed726ad87d7eCC1!$7d8&CcL !) Dialo,(B*o,inB)5:inButton(BO[B)5Clic> #) 'nd I4 $) :indo6(B/li,+t 0eser7ationB)53cti7ate %) :indo6(B/li,+t 0eser7ationB)5:inButton(BButtonB)5Clic> 1)):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)53cti7ate 11)oeG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5&et0O-roperty (B'nabledB) 12)ceG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5&et0O-roperty (B'nabledB) 13)4eG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5&et0O-roperty(B'nabledB) 14)ocG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5&et0O-roperty (BC+ec>edB) 1 )ccG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5&et0O-roperty (BC+ec>edB) 1!)4cG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5&et0O-roperty(BC+ec>edB) 1#)I4 (oeGtrue and ceGtrue and 4eGtrue) and (ocGBO//B and ccGBO//B and 4cGBO//B) T+en 1$)0eporter50eport'7ent )<B0esB<B-assB 1%)else 2))0eporter50eport'7ent 1<B0esB<B/ailB 21)'nd I4 22):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO@B 23)onoG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5&et0O-roperty (BC+ec>edB) 24)I4 onoGBO@B T+en 2 )4dG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5&et0O-roperty (B'nabledB) 2!)onoG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5&et0O-roperty (B'nabledB) 2#)4dG4alse 2$)onoG4alse 2%)0eporter50eport'7ent )<B0esB<B-assB

53

3))else 31)0eporter50eport'7ent 1<B0esB<B/ailB 32)'nd I4 33):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5Set BO//B 34):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5Set BO@B 3 )cnG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5&et0O-roperty (BC+ec>edB) 3!)I4 cnGBO@B T+en 3#)onoG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5&et0O-roperty (B'nabledB) 3$)4dG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5&et0O-roperty (B'nabledB) 3%)4dGTrue 4))onoG4alse 41)0eporter50eport'7ent )<B0esB<B-assB 42)else 43)0eporter50eport'7ent 1<B0esB<B/ailB 44)'nd I4 4 ):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5Set BO//B 4!):indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5Set BO@B 4#)4dG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((B/li,+t DateB)5&et0O-roperty (BC+ec>edB) 4$)I4 4dGBO@B T+en 4%)onoG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BOrder @o5B)5&et0O-roperty (B'nabledB) ))cnG:indo6(B/li,+t 0eser7ationB)5Dialo,(BOpen OrderB)5:inC+ec>Bo((BCustomer @ameB)5&et0O-roperty (B'nabledB) 1)cnGTrue 2)onoG4alse 3)0eporter50eport'7ent )<B0esB<B-assB 4)else )0eporter50eport'7ent 1<B0esB<B/ailB !)'nd I4 1$) In 5ogin 1ia%og &o+? /eri(* He%p #essage (T+e messa,e is XT+e pass6ord is 98'0CH0L9)

54

1) I4 @ot Dialo,(B*o,inB)5'(ist (2) T+en 2) S*ste#-ti%.3un LC)OProgra# ;i%esO<ercur* InteractiveOQuic.Test Pro(essiona%Osa#p%esO(%ightOappO(%ight$a.e+eL 3) 'nd I4 4) Dialo,(B*o,inB)53cti7ate ) Dialo,(B*o,inB)5:inButton(B;elpB)5Clic> !) messa,eGDialo,(B*o,inB)5Dialo,(B/li,+t 0eser7ationsB)5Static(BT+e pass6ord is 98'0CH0L9B)5&et0O-roperty(Bte(tB) #) I4 messa,eGBT+e pass6ord is 98'0CH0L9B T+en $) 0eporter50eport'7ent )<B0esB<BCorrect messa,e BPmessa,e %) else 1))0eporter50eport'7ent 1<B0esB<B:orn, messa,e B 11)'nd I4 14) Count a%% opened 0rowsers on des.top and c%ose the# a%%> 1) Set oDesc G Description5Create() 2) oDesc(BmicclassB)5Value G BBro6serB 3) Set Bro6sers GDes>top5C+ildOb?ects (oDesc) 4) @umbero4Bro6sers G Bro6sers5Count() ) 0eporter50eport'7ent 2<B0esB<B@umber o4 Bro6sers areF BP@umberO4Bro6sers !) /or CounterG) to @umbero4Bro6sers.1 #) Bro6sers(Counter)5Close $) @e(t 16) Create an "+ce% (i%e? enter so#e data and save the (i%e through /0 scripting> 1) Dim ob?e(cel 2) Set ob?'(cel G createob?ect(B'(cel5applicationB) 3) ob?e(cel5Visible G True 4) ob?e(cel5:or>boo>s5add ) ob?e(cel5Cells(1< 1)5Value G BTestin,B !) ob?e(cel53cti7e:or>boo>5Sa7e3s(B4FOe(celtest5(lsB) #) ob?e(cel52uit

55

QTP Add@Ins In(or#ation


I) ActiveP "nviron#ent 2&Aect 3cti7eD 3c(Button 3c(Calendar 3c(C+ec>Bo( 3c(ComboBo( 3c('dit 3c(0adioButton 3c(Table 3c(Htil 1escription 3n 3cti7eD control5 3n 3cti7eD button5 3n 3cti7eD calendar ob?ect5 3n 3cti7eD c+ec> bo(5 3n 3cti7eD combo bo( ob?ect5 3n 3cti7eD edit bo(5 3n 3cti7eD radio button5 3n 3cti7eD table5 3n ob?ect t+at enables you to 6or> 6it+ ob?ects returned by per4ormin, an operation (usually 7ia t+e Ob?ect property) on an 3cti7eD test ob?ect5

II) 1e%phi "nviron#ent

56

2&Aect Delp+iButton Delp+iC+ec>Bo( Delp+iComboBo( Delp+i'dit Delp+i'ditor Delp+i*ist Delp+i*istVie6 Delp+i@a7i,ator Delp+iOb?ect Delp+i0adioButton Delp+iScrollBar Delp+iSpin Delp+iStatic Delp+iStatusBar Delp+iTable Delp+iTabStrip Delp+iTreeVie6 Delp+i:indo6

3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i Delp+i

1escription button5 c+ec> bo(5 combo bo(5 edit bo(5 multi.line editor5 list5 list.7ie6 control5 na7i,ator control5 ob?ect5 radio button5 scroll bar5 spin bo(5 static control5 status bar5 table5 tab strip5 tree.7ie6 control5 6indo6 or dialo, bo(5

III) Mava "nviron#ent 2&Aect Ca7a3pplet Ca7aButton Ca7aCalendar Ca7aC+ec>Bo( Ca7aDialo, Ca7a'dit Ca7a'(pandBar Ca7aInternal/rame Ca7a*in> Ca7a*ist Ca7a8enu Ca7aOb?ect 1escription 3 Ca7a applet5 3 Ca7a button5 3 Ca7a calendar5 3 Ca7a c+ec> bo(5 3 Ca7a dialo, bo(5 3 Ca7a edit bo(5 3 Ca7a control t+at contains labeled bar items< 6+ic+ can be e(panded or collapsed by t+e user5 3n internal 4rame t+at can be acti7ated 4rom t+e Ca7a applet5 3 Ca7a control t+at displays te(t 6it+ lin>s5 3 Ca7a list bo( 6it+ sin,le or multiple selection5 3 Ca7a menu item5 3 ,eneric Ca7a ob?ect5

57

Ca7a0adioButton Ca7aSlider Ca7aSpin Ca7aStaticTe(t Ca7aTab Ca7aTable Ca7aToolbar Ca7aTree Ca7a:indo6

3 Ca7a radio button5 3 Ca7a slider5 3 Ca7a spin ob?ect5 3 Ca7a static te(t ob?ect5 3 Ca7a tabstrip control containin, tabbed panels5 3 Ca7a table5 3 Ca7a toolbar5 3 Ca7a tree5 3 Ca7a 6indo65

I/) . "T We& ;or#s "nviron#ent 2&Aect :b4Calendar :b4&rid :b4TabStrip :b4Toolbar :b4TreeVie6 :b4Hltra&rid 1escription :eb /orms calendar control5 :eb /orms Data&rid ob?ect5 :eb /orms tabstrip control5 :eb /orms toolbar control5 :eb /orms tree 7ie6 ob?ect5 :eb /orms Hltra&rid ob?ect5

3 3 3 3 3 3

5@'T 5@'T 5@'T 5@'T 5@'T 5@'T

/) . "T Windows ;or#s "nviron#ent 2&Aect S64Button S64Calendar S64C+ec>Bo( S64ComboBo( S64'dit S64'ditor S64*abel S64*ist S64*istVie6 S64Ob?ect S64-roperty&rid S640adioButton S64ScrollBar S64Spin 1escription 3 5@'T :indo6s /orms button ob?ect5 3 DateTime-ic>er or a 8ont+ Calendar 5@'T :indo6s /orms calendar ob?ect5 3 5@'T :indo6s /orms c+ec> bo(5 3 5@'T :indo6s /orms combo bo(5 3 5@'T :indo6s /orms edit bo(5 3 5@'T :indo6s /orms multi.line edit bo(5 3 5@'T :indo6s /orms static te(t ob?ect5 3 5@'T :indo6s /orms list5 3 5@'T :indo6s /orms *istVie6 control5 3 standard 5@'T :indo6s /orms ob?ect5 3 property ,rid control based on t+e 5@'T :indo6s /orms library5 3 5@'T :indo6s /orms radio button5 3 5@'T :indo6s /orms scroll bar5 3 5@'T :indo6s /orms spin ob?ect5

58

S64StatusBar S64Tab S64Table S64ToolBar S64TreeVie6 S64:indo6

3 5@'T :indo6s /orms 3 5@'T :indo6s /orms 3 ,rid control based on library5 3 5@'T :indo6s /orms 3 5@'T :indo6s /orms 3 5@'T :indo6s /orms

status bar control5 tab control5 t+e 5@'T :indo6s /orms toolbar5 TreeVie6 control5 6indo65

/I) Windows Presentation ;oundation "nviron#ent 2&Aect :p4Button :p4C+ec>Bo( :p4ComboBo( :p4'dit :p4&rid :p4Ima,e :p4*in> :p4*ist :p48enu :p4Ob?ect :p4-ro,ressBar :p40adioButton :p4ScrollBar :p4Slider :p4StatusBar 1escription 3 button control in a :indo6s -resentation /oundation application5 3 c+ec> bo( control in a :indo6s -resentation /oundation application5 3 combo bo( control in a :indo6s -resentation /oundation application5 3 document< ric+ te(t bo(< or te(t control in a :indo6s -resentation /oundation application5 3 ,rid control in a :indo6s -resentation /oundation application5 3n ima,e control in a :indo6s -resentation /oundation application5 3 +yperlin> control in a :indo6s -resentation /oundation application5 3 list control in a :indo6s -resentation /oundation application5 3 menu control in a :indo6s -resentation /oundation application5 3n ob?ect control in a :indo6s -resentation /oundation application5 3 pro,ress bar control in a :indo6s -resentation /oundation application5 3 radio button control in a :indo6s -resentation /oundation application5 3 scroll bar control in a :indo6s -resentation /oundation application5 3 slider control in a :indo6s -resentation /oundation application5 3 status bar control in a :indo6s -resentation

59

:p4TabStrip :p4Toolbar :p4TreeVie6 :p4:indo6

/oundation application5 3 tab control in a :indo6s -resentation /oundation application5 3 toolbar control in a :indo6s -resentation /oundation application5 3 tree control in a :indo6s -resentation /oundation application5 3 6indo6 control in a :indo6s -resentation /oundation application5

/II) 2rac%e "nviron#ent 2&Aect Oracle3pplications OracleButton OracleCalendar OracleC+ec>bo( Oracle/le(:indo6 Oracle/orm:indo6 Oracle*ist 1escription 3n Oracle 3pplications session 6indo65 3n Oracle button5 3n Oracle calendar5 3 c+ec> bo( Oracle 4ield5 3n Oracle 4le(4ield 6indo65 3n Oracle /orm 6indo65 3n Oracle poplist (combo bo() or list5 3n Oracle 6indo6 containin, a list o4 7alues 4or Oracle*istO4Values selection5 Oracle*o,on 3n Oracle 3pplications si,n.on 6indo65 Oracle@a7i,ator 3n Oracle @a7i,ator 6indo65 Oracle@oti4ication 3n Oracle error or messa,e 6indo65 Oracle0adio&roup 3n Oracle option (radio button) ,roup5 T+e status line and messa,e line at t+e bottom o4 OracleStatus*ine an Oracle 3pplications 6indo65 OracleTabbed0e,ion 3n Oracle tabbed re,ion5 OracleTable 3n Oracle bloc> o4 records5 OracleTe(t/ield 3n Oracle te(t 4ield5 OracleTree 3n Oracle tree5 /III) Peop%eSo(t "nviron#ent 2&Aect -S/rame 1escription 3 4rame ob?ect 6it+in a -eopleSo4t application5

IP) Power0ui%der "nviron#ent

60

2&Aect -bButton -bC+ec>Bo( -bComboBo( -bData:indo6 -b'dit -b*ist -b*istVie6 -bOb?ect -b0adioButton -bScrollBar -bTabStrip -bTreeVie6 -b:indo6

3 3 3 3 3 3 3 3 3 3 3 3 3

1escription -o6erBuilder button5 -o6erBuilder c+ec> bo(5 -o6erBuilder combo bo(5 -o6erBuilder Data:indo6 control5 -o6erBuilder edit bo(5 -o6erBuilder list5 -o6erBuilder list7ie6 control5 standard -o6erBuilder ob?ect5 -o6erBuilder radio button5 -o6erBuilder scroll bar5 -o6erBuilder tab strip control -o6erBuilder tree.7ie6 control5 -o6erBuilder 6indo65

P) SAP We& "nviron#ent 2&Aect S3-Button S3-Calendar S3-C+ec>Bo( S3-DropDo6n8enu S3-'dit S3-/rame S3-iVie6 S3-*ist S3-8enu S3-@a7i,ationBar S3-O[Code S3--ortal S3-0adio&roup 1escription 3n S3- &ui 4or ;T8* application button< includin, icons< toolbar buttons< re,ular buttons< buttons 6it+ te(t< and buttons 6it+ te(t and ima,e5 3 calendar in a :eb.based S3- application5 3n S3- &ui 4or ;T8* application to,,le button< includin, c+ec> bo(es and to,,le ima,es5 3 menu t+at is opened by clic>in, a menu icon 6it+in an S3- &ui 4or ;T8* application5 3n S3- &ui 4or ;T8* application edit bo(< includin, sin,le.line edit bo(es and multi.line edit bo(es (te(t area)5 3n S3- &ui 4or ;T8* application 4rame5 3n S3- 'nterprise -ortal application iVie6 4rame5 3 drop.do6n or sin,le"multiple selection list in an S3- &ui 4or ;T8* application5 3n S3- &ui 4or ;T8* application top.le7el menu5 3 na7i,ation bar in a :eb.based S3- application5 3n O[ Code bo( in an S3- &ui 4or ;T8* application5 3n S3- 'nterprise -ortal des>top5 3n S3- &ui 4or ;T8* application radio button ,roup5

61

S3-StatusBar S3-Table S3-TabStrip S3-TreeVie6

3n S3- &ui 4or ;T8* application status bar5 3n S3- &ui 4or ;T8* application table or ,rid5 3n S3- &ui 4or ;T8* application tab strip ob?ect (an ob?ect t+at enables s6itc+in, bet6een multiple tabs)5 3n S3- &ui 4or ;T8* application tree ob?ect5

PI) SAP J-I (or Windows "nviron#ent 2&Aect S3-&ui3-O&rid S3-&uiButton S3-&uiCalendar S3-&uiC+ec>Bo( S3-&uiComboBo( S3-&ui'dit S3-&ui'lement S3-&ui&rid S3-&ui*abel S3-&ui8enubar S3-&uiO[Code S3-&ui0adioButton S3-&uiSession S3-&uiStatusBar S3-&uiTable S3-&uiTabStrip 1escription 3n 3-O ,rid control in an S3- &HI 4or :indo6s application5 3 button in an S3- &HI 4or :indo6s application5 3 calendar ob?ect in an S3- &HI 4or :indo6s application5 3 c+ec> bo( in an S3- &HI 4or :indo6s application5 3 combo bo( in an S3- &HI 4or :indo6s application5 3n edit bo( in an S3- &HI 4or :indo6s application5 3ny ob?ect in an S3- &HI 4or :indo6s application5 3 ,rid control in an S3- &HI 4or :indo6s application5 3 static te(t label in an S3- &HI 4or :indo6s application5 3 menu bar in an S3- &HI 4or :indo6s application5 3n O[ Code bo( in an S3- &HI 4or :indo6s application5 3 radio button in an S3- &HI 4or :indo6s application5 0epresents t+e S3- &HI 4or :indo6s session on 6+ic+ an operation is per4ormed5 3 status bar in an S3- &HI 4or :indo6s application5 3 table control in an S3- &HI 4or :indo6s application5 3 tab strip in an S3- &HI 4or :indo6s application5

62

S3-&uiTe(t3rea S3-&uiToolbar S3-&uiTree S3-&uiHtil S3-&ui:indo6

3 te(t area in an S3- &HI 4or :indo6s application5 3 toolbar in an S3- &HI 4or :indo6s application5 3 column tree< list tree< or simple tree control in an S3- &HI 4or :indo6s application5 3 utility ob?ect in an S3- &HI 4or :indo6s application5 3 6indo6 or dialo, bo( containin, ob?ects in an S3- &HI 4or :indo6s application5

PII) Sie&e% "nviron#ent 1escription 3n edit bo( 6+ose 7alue can be set by a Sbl3d7anced'dit dynamic ob?ect t+at opens a4ter clic>in, on a button inside t+e edit bo( SblButton 3 Siebel button5 SblC+ec>Bo( 3 c+ec> bo( 6it+ an O@ and O// state5 Sbl'dit 3n edit bo(5 Sbl-ic>*ist 3 drop.do6n pic> list5 3 Siebel table containin, a 7ariable SblTable number o4 ro6s and columns5 3 number o4 tabs and 4our arro6s t+at SblTabStrip mo7e its 7isible ran,e to t+e le4t and to t+e ri,+t5 SblTreeVie6 3 tree 7ie6 o4 speci4ic screen data5 3n applet in a Siebel test automation Sieb3pplet en7ironment5 3n application in a Siebel test automation Sieb3pplication en7ironment5 3 button control in a Siebel test SiebButton automation en7ironment5 3 calculator control in a Siebel test SiebCalculator automation en7ironment5 3 calendar control in a Siebel test SiebCalendar automation en7ironment5 3 c+ec>bo( in a Siebel test automation SiebC+ec>bo( en7ironment5 T+e communications toolbar in a Siebel SiebCommunicationsToolbar test automation en7ironment5 SiebCurrency 3 currency calculator in a Siebel test 2&Aect

63

Sieb*ist Sieb8enu Sieb-a,eTabs Sieb-D2 Sieb-ic>list Sieb0ic+Te(t SiebScreen SiebScreenVie6s SiebTas>3ssistant SiebTas>HI-ane SiebTe(t SiebTe(t3rea SiebT+readbar SiebToolbar SiebTree SiebVie6 SiebVie63pplets

automation en7ironment5 3 list ob?ect in a Siebel test automation en7ironment5 3 menu or menu item in a Siebel test automation en7ironment5 3 pa,e tab in a Siebel test automation en7ironment5 3 prede4ined 1uery in a Siebel test automation en7ironment5 3 pic> list in a Siebel test automation en7ironment5 3 ric+ te(t control in a Siebel test automation en7ironment5 3 screen ob?ect in a Siebel test automation en7ironment5 3 screen 7ie6 in a Siebel test automation en7ironment5 T+e Tas> 3ssistant in a Siebel test automation en7ironment5 T+e tas> HI pane in a Siebel test automation en7ironment5 3 te(t bo( in a Siebel test automation en7ironment5 3 te(t area in a Siebel test automation en7ironment5 3 t+readbar in a Siebel test automation en7ironment5 3 toolbar in a Siebel test automation en7ironment5 3 tree 7ie6 ob?ect in a Siebel test automation en7ironment5 3 7ie6 ob?ect in a Siebel test automation en7ironment5 3 7ie6 applet in a Siebel test automation en7ironment5

PIII) Standard Windows "nviron#ent 2&Aect 1escription

64

Des>top Dialo, Static SystemHtil :inButton :inCalendar :inC+ec>Bo( :inComboBo( :indo6 :in'dit :in'ditor :in*ist :in*istVie6 :in8enu :inOb?ect :in0adioButton :inScrollBar :inSpin :inStatusBar :inTab :inToolbar :inTreeVie6

3n ob?ect t+at enables you to access top.le7el items on your des>top5 3 :indo6s dialo, bo(5 3 static te(t ob?ect5 3n ob?ect used to control applications and processes durin, a run session5 3 :indo6s button5 3 :indo6s calendar5 3 :indo6s c+ec> bo(5 3 :indo6s combo bo(5 3 standard 6indo65 3 :indo6s edit bo(5 3 :indo6s multi.line editor5 3 :indo6s list5 3 :indo6s list.7ie6 control5 3 :indo6s menu5 3 standard (:indo6s) ob?ect5 3 :indo6s radio button5 3 :indo6s scroll bar5 3 :indo6s spin bo(5 3 :indo6s status bar5 3 :indo6s tab strip in a dialo, bo(5 3 :indo6s toolbar5 3 :indo6s tree.7ie6 control5

PI/) Stingra* "nviron#ent 2&Aect :inTab :inTable :inToolbar :inTreeVie6 1escription :indo6s tab strip in a dialo, bo(5 Stin,ray ,rid5 :indo6s toolbar5 Stin,ray tree control5

3 3 3 3

P/) Ter#ina% "#u%ators "nviron#ent 2&Aect Te/ield TeScreen 1escription 3 terminal emulator 4ield t+at 4ully supports ;**3-I5 3 terminal emulator screen t+at 4ully supports ;**3-I5

65

TeTe(tScreen Te:indo6

3 terminal emulator screen t+at uses te(t.only ;**3-I or does not support ;**3-I5 3 terminal emulator 6indo65

P/I) /isua% 0asic "nviron#ent 2&Aect VbButton VbC+ec>Bo( VbComboBo( Vb'dit Vb'ditor Vb/rame Vb*abel Vb*ist Vb*istVie6 Vb0adioButton VbScrollBar VbToolbar VbTreeVie6 Vb:indo6 1escription Visual Basic button5 Visual Basic c+ec> bo(5 Visual Basic combo bo(5 Visual Basic edit bo(5 Visual Basic multi.line editor5 Visual Basic 4rame5 static te(t ob?ect5 Visual Basic list5 Visual Basic list.7ie6 control5 Visual Basic radio button5 Visual Basic scroll bar5 Visual Basic toolbar5 Visual Basic tree.7ie6 control5 Visual Basic 6indo65

3 3 3 3 3 3 3 3 3 3 3 3 3 3

P/II) /isua%Age S#a%%ta%. "nviron#ent 2&Aect :inButton :in'dit :in*ist :inOb?ect :inTab :inTable :inTreeVie6 1escription 3 button in t+e Visual3,e Smalltal> application5 3n edit bo( in t+e Visual3,e Smalltal> application5 3 list in t+e Visual3,e Smalltal> application5 3n ob?ect in t+e Visual3,e Smalltal> application5 3 tab strip in t+e Visual3,e Smalltal> application5 3 table in t+e Visual3,e Smalltal> application5 3 tree.7ie6 control in t+e Visual3,e Smalltal> application5

P/III) We& "nviron#ent 2&Aect Bro6ser /rame Ima,e 1escription 3 :eb bro6ser (or bro6ser tab)5 3n ;T8* 4rame5 3n ima,e 6it+ or 6it+out a tar,et H0* lin>5

66

*in> -a,e Vie6*in> :eb3rea :ebButton :ebC+ec>Bo( :eb'dit :eb'lement :eb/ile :eb*ist :eb0adio&roup :ebTable :ebD8*

3 +yperte(t lin>5 3n ;T8* pa,e5 3 Vie6lin> ob?ect5 3 section o4 an ima,e (usually a section o4 a client.side ima,e map)5 3n ;T8* button5 3 c+ec> bo( 6it+ an O@ and O// state5 3n edit bo(< usually contained inside a 4orm5 3 ,eneral :eb ob?ect t+at can represent any :eb ob?ect5 3n edit bo( 6it+ a bro6se button attac+ed< used to select a 4ile 4rom t+e /ile dialo, bo(5 3 drop.do6n bo( or multiple selection list5 3 set o4 radio buttons belon,in, to t+e same ,roup5 3 table containin, a 7ariable number o4 ro6s and columns5 3n D8* document contained in a :eb pa,e5

PIP) We& Services "nviron#ent 2&Aect 3ttac+ments Con4i,uration +eaders Security :ebSer7ice :SHtil 1escription 3n ob?ect t+at supports attac+ment.related test ob?ect operations5 3n ob?ect t+at supports con4i,uration.related test ob?ect operations5 3n ob?ect t+at supports +eader.related test ob?ect operations5 3n ob?ect t+at supports security.related test ob?ect operations5 3 test ob?ect representin, a :eb ser7ice5 3 utility ob?ect used to c+ec> :SD* 4iles5

0) -ti%it* 2&Aects

Crypt Ob?ect DataTable Ob?ect Description Ob?ect Dot@et/actory Ob?ect

67

DT-arameter Ob?ect DTS+eet Ob?ect 'n7ironment Ob?ect '(tern Ob?ect *ocal-arameter Ob?ect 8ercuryTimers Ob?ect (Collection) 8ercuryTimer Ob?ect -arameter Ob?ect -at+/inder Ob?ect -roperties Ob?ect (Collection) 2CHtil Ob?ect 0andom@umber Ob?ect 0eco7ery Ob?ect 0eporter Ob?ect 0epositoriesCollection Ob?ect 0epository Ob?ect Ser7ices Ob?ect Settin, Ob?ect System8onitor Ob?ect Te(tHtil Ob?ect TS*Test Ob?ect D8*Htil Ob?ect

T+e 4ollo6in, utility statements +elp you control your test5


Describe0esult Statement '(ecute/ile Statement '(it3ction Statement '(it3ctionIteration Statement '(itComponent Statement '(itComponentIteration Statement

68

'(itTest Statement '(itTestIteration Statement &et*ast'rror Statement In7o>e3pplication Statement *oad3nd0un3ction Statement 8anualStep Statement -rint Statement 0e,isterHser/unc Statement 0un3ction Statement Set*ast'rror Statement Hnre,isterHser/unc Statement :ait Statement

C) Supp%e#enta% 2&Aects

DbTable Ob?ect VirtualButton Ob?ect VirtualC+ec>Bo( Ob?ect Virtual*ist Ob?ect VirtualOb?ect Ob?ect Virtual0adioButton Ob?ect VirtualTable Ob?ect D8*3ttribute Ob?ect D8*3ttributesColl Ob?ect D8*Data Ob?ect D8*'lement Ob?ect D8*'lementsColl Ob?ect D8*/ile Ob?ect D8*ItemColl Ob?ect

69

/0Script J%ossar*
ActiveP contro% 3n ob?ect t+at you place on a 4orm to enable or en+ance a user9s interaction 6it+ an application5 3cti7eD controls +a7e e7ents and can be incorporated into ot+er controls5 T+e controls +a7e an 5oc( 4ile name e(tension5 ActiveP o&Aect 3n ob?ect t+at is e(posed to ot+er applications or pro,rammin, tools t+rou,+ 3utomation inter4aces5 Argu#ent 3 constant< 7ariable< or e(pression passed to a procedure5

70

Arra* 3 set o4 se1uentially inde(ed elements +a7in, t+e same type o4 data5 'ac+ element o4 an array +as a uni1ue identi4yin, inde( number5 C+an,es made to one element o4 an array do not a44ect t+e ot+er elements5 ASCII Character Set 3merican Standard Code 4or In4ormation Interc+an,e (3SCII) #.bit c+aracter set 6idely used to represent letters and symbols 4ound on a standard H5S5 >eyboard5 T+e 3SCII c+aracter set is t+e same as t+e 4irst 12$ c+aracters ()\ 12#) in t+e 3@SI c+aracter set5 Auto#ation o&Aect 3n ob?ect t+at is e(posed to ot+er applications or pro,rammin, tools t+rou,+ 3utomation inter4aces5 0itwise co#parison 3 bit.by.bit comparison o4 identically positioned bits in t6o numeric e(pressions5 0oo%ean e+pression 3n e(pression t+at e7aluates to eit+er True or ;a%se5 0* re(erence 3 6ay o4 passin, t+e address< rat+er t+an t+e 7alue< o4 an ar,ument to a procedure5 T+is allo6s t+e procedure to access t+e actual 7ariable5 3s a result< t+e 7ariable9s actual 7alue can be c+an,ed by t+e procedure to 6+ic+ it is passed5 0* va%ue 3 6ay o4 passin, t+e 7alue< rat+er t+an t+e address< o4 an ar,ument to a procedure5 T+is allo6s t+e procedure to access a copy o4 t+e 7ariable5 3s a result< t+e 7ariable9s actual 7alue can9t be c+an,ed by t+e procedure to 6+ic+ it is passed5 character code 3 number t+at represents a particular c+aracter in a set< suc+ as t+e 3SCII c+aracter set5 C%ass T+e 4ormal de4inition o4 an ob?ect5 T+e class acts as t+e template 4rom 6+ic+ an instance o4 an ob?ect is created at run time5 T+e class de4ines t+e properties o4 t+e ob?ect and t+e met+ods used to control t+e ob?ect9s be+a7ior5

71

C%ass #odu%e 3 module containin, t+e de4inition o4 a class (its property and met+od de4initions)5 Co%%ection 3n ob?ect t+at contains a set o4 related ob?ects5 3n ob?ect9s position in t+e collection can c+an,e 6+ene7er a c+an,e occurs in t+e collectionE t+ere4ore< t+e position o4 any speci4ic ob?ect in t+e collection may 7ary5 Co##ent Te(t added to code by a pro,rammer t+at e(plains +o6 t+e code 6or>s5 In Visual Basic Scriptin, 'dition< a comment line ,enerally starts 6it+ an apostrop+e (Q)< or you can use t+e >ey6ord 3e# 4ollo6ed by a space5 Co#parison operator 3 c+aracter or symbol indicatin, a relations+ip bet6een t6o or more 7alues or e(pressions5 T+ese operators include less t+an (Q)< less t+an or e1ual to (QG)< ,reater t+an (R)< ,reater t+an or e1ual to (RG)< not e1ual (QR)< and e1ual (G)5 Is is also a comparison operator< but it is used e(clusi7ely 4or determinin, i4 one ob?ect re4erence is t+e same as anot+er5

Constant 3 named item t+at retains a constant 7alue t+rou,+out t+e e(ecution o4 a pro,ram5 Constants can be used any6+ere in your code in place o4 actual 7alues5 3 constant can be a strin, or numeric literal< anot+er constant< or any combination t+at includes arit+metic or lo,ical operators e(cept Is and e(ponentiation5 /or e(ampleF Const 3 G B8yStrin,B 1ata ranges 'ac+ Variant subtype +as a speci4ic ran,e o4 allo6ed 7aluesF Su&t*pe 0*te 0oo%ean Integer 5ong Sing%e 3ange ) to 2 5

True or ;a%se5 .32<#!$ to 32<#!#5 .2<14#<4$3<!4$ to 2<14#<4$3<!4#5 .354)2$23'3$ to .154)12%$'.4 4or ne,ati7e 7aluesE

72

154)12%$'.4 to 354)2$23'3$ 4or positi7e 7alues5 1ou&%e .15#%#!%3134$!232'3)$ to .45%4)! !4 $4124#'.324 4or ne,ati7e 7aluesE 45%4)! !4 $4124#'.324 to 15#%#!%3134$!232'3)$ 4or positi7e 7alues5

Currenc* .%22<33#<2)3<!$ <4##5 $)$ to %22<33#<2)3<!$ <4##5 $)#5 1ate 2&Aect String Canuary 1< 1)) to December 31< %%%%< inclusi7e5 3ny 2&Aect re4erence5 Variable.len,t+ strin,s may ran,e in len,t+ 4rom ) to appro(imately 2 billion c+aracters5

1ate e+pression 3ny e(pression t+at can be interpreted as a date5 T+is includes any combination o4 date literals< numbers t+at loo> li>e dates< strin,s t+at loo> li>e dates< and dates returned 4rom 4unctions5 3 date e(pression is limited to numbers or strin,s< in any combination< t+at can represent a date 4rom Canuary 1< 1)) t+rou,+ December 31< %%%%5 Dates are stored as part o4 a real number5 Values to t+e le4t o4 t+e decimal represent t+e dateE 7alues to t+e ri,+t o4 t+e decimal represent t+e time5 @e,ati7e numbers represent dates prior to December 3)< 1$%%5

1ate %itera% 3ny se1uence o4 c+aracters 6it+ a 7alid 4ormat t+at is surrounded by number si,ns (T)5 Valid 4ormats include t+e date 4ormat speci4ied by t+e locale settin,s 4or your code or t+e uni7ersal date 4ormat5 /or e(ample< T12"31"%%T is t+e date literal t+at represents December 31< 1%%%< 6+ere 'n,lis+.H5S5 is t+e locale settin, 4or your application5 In VBScript< t+e only reco,niIed 4ormat is HS.'@&*IS;< re,ardless o4 t+e actual locale o4 t+e user5 T+at is< t+e interpreted 4ormat is mm"dd"yyyy5

1ate separators C+aracters used to separate t+e day< mont+< and year 6+en date 7alues are 4ormatted5 "#pt*

3 7alue t+at indicates t+at no be,innin, 7alue +as been assi,ned to a 7ariable5 "#pt* 7ariables are ) in a numeric conte(t< or Iero.len,t+ in a strin, conte(t5

73

"rror nu#&er 3 6+ole number in t+e ran,e ) to ! < 3 < inclusi7e< t+at corresponds to t+e u#&er property o4 t+e "rr ob?ect5 :+en combined 6it+ t+e a#e property o4 t+e "rr ob?ect< t+is number represents a particular error messa,e5 "+pression 3 combination o4 >ey6ords< operators< 7ariables< and constants t+at yield a strin,< number< or ob?ect5 3n e(pression can per4orm a calculation< manipulate c+aracters< or test data5 Intrinsic constant 3 constant pro7ided by an application5 Because you can9t disable intrinsic constants< you can9t create a user.de4ined constant 6it+ t+e same name5 Re*word 3 6ord or symbol reco,niIed as part o4 t+e VBScript lan,ua,eE 4or e(ample< a statement< 4unction name< or operator5 5oca%e T+e set o4 in4ormation t+at corresponds to a ,i7en lan,ua,e and country5 3 locale a44ects t+e lan,ua,e o4 prede4ined pro,rammin, terms and locale. speci4ic settin,s5 T+ere are t6o conte(ts 6+ere locale in4ormation is importantF T+e code locale a44ects t+e lan,ua,e o4 terms suc+ as >ey6ords and de4ines locale.speci4ic settin,s suc+ as t+e decimal and list separators< date 4ormats< and c+aracter sortin, order5 T+e system locale a44ects t+e 6ay locale.a6are 4unctionality be+a7es< 4or e(ample< 6+en you display numbers or con7ert strin,s to dates5 Lou set t+e system locale usin, t+e Control -anel utilities pro7ided by t+e operatin, system5 othing T+e special 7alue t+at indicates t+at an ob?ect 7ariable is no lon,er associated 6it+ any actual ob?ect5 u%%

3 7alue indicatin, t+at a 7ariable contains no 7alid data5 u%% is t+e result o4F 3n e(plicit assi,nment o4 u%% to a 7ariable5 3ny operation bet6een e(pressions t+at contain u%%5

u#eric e+pression

74

3ny e(pression t+at can be e7aluated as a number5 'lements o4 t+e e(pression can include any combination o4 >ey6ords< 7ariables< constants< and operators t+at result in a number5 2&Aect t*pe 3 type o4 ob?ect e(posed by an application< 4or e(ample< 3pplication< /ile< 0an,e< and S+eet5 0e4er to t+e application9s documentation (8icroso4t '(cel< 8icroso4t -ro?ect< 8icroso4t :ord< and so on) 4or a complete listin, o4 a7ailable ob?ects5 pi

-i is a mat+ematical constant e1ual to appro(imately 35141 %2! 3 $%#%325

Private Variables t+at are 7isible only to t+e script in 6+ic+ t+ey are declared5 Procedure 3 named se1uence o4 statements e(ecuted as a unit5 /or e(ample< ;unction and Su& are types o4 procedures5 Procedure %eve% Describes statements located 6it+in a ;unction or Su& procedure5 Declarations are usually listed 4irst< 4ollo6ed by assi,nments and ot+er e(ecutable code5 /or e(ampleF Sub 8ySub() 9 T+is statement declares a sub procedure bloc>5 Dim 3 9 T+is statement starts t+e procedure bloc>5 3 G B8y 7ariableB 9 -rocedure.le7el code5 Debu,5-rint 3 9 -rocedure.le7el code5 'nd Sub 9 T+is statement ends a sub procedure bloc>5 @ote t+at script.le7el code resides outside any procedure bloc>s5

Propert* 3 named attribute o4 an ob?ect5 -roperties de4ine ob?ect c+aracteristics suc+ as siIe< color< and screen location< or t+e state o4 an ob?ect< suc+ as enabled or disabled5 Pu&%ic Variables declared usin, t+e Pu&%ic Statement are 7isible to all procedures in all modules in all applications5 3un ti#e T+e time 6+en code is runnin,5 Durin, run time< you can9t edit t+e code5

75

3un@ti#e error 3n error t+at occurs 6+en code is runnin,5 3 run.time error results 6+en a statement attempts an in7alid operation5 Scope De4ines t+e 7isibility o4 a 7ariable< procedure< or ob?ect5 /or e(ample< a 7ariable declared as Pu&%ic is 7isible to all procedures in all modules5 Variables declared in procedures are 7isible only 6it+in t+e procedure and lose t+eir 7alue bet6een calls5 SC21" 3 lon, inte,er 7alue t+at is used to pass detailed in4ormation to t+e caller o4 an inter4ace member or 3-I 4unction5 T+e status codes 4or O*' inter4aces and 3-Is are de4ined in /3CI*ITLZIT/5 Script %eve% 3ny code outside a procedure is re4erred to as script.le7el code5 Seed

3n initial 7alue used to ,enerate pseudorandom numbers5 /or e(ample< t+e 3ando#iDe statement creates a seed number used by t+e 3nd 4unction to create uni1ue pseudorandom number se1uences5

String co#parison 3 comparison o4 t6o se1uences o4 c+aracters5 Hnless speci4ied in t+e 4unction ma>in, t+e comparison< all strin, comparisons are binary5 In 'n,lis+< binary comparisons are case.sensiti7eE te(t comparisons are not5

String e+pression 3ny e(pression t+at e7aluates to a se1uence o4 conti,uous c+aracters5 'lements o4 a strin, e(pression can include a 4unction t+at returns a strin,< a strin, literal< a strin, constant< or a strin, 7ariable5 T*pe %i&rar* 3 4ile or component 6it+in anot+er 4ile t+at contains standard descriptions o4 e(posed ob?ects< properties< and met+ods5 /aria&%e

76

3 named stora,e location t+at can contain data t+at can be modi4ied durin, pro,ram e(ecution5 'ac+ 7ariable +as a name t+at uni1uely identi4ies it 6it+in its le7el o4 scope5 Variable namesF 8ust be,in 6it+ an alp+abetic c+aracter5 Can9t contain an embedded period or type.declaration c+aracter5 8ust be uni1ue 6it+in t+e same scope5 8ust be no lon,er t+an 2 c+aracters5

77

Das könnte Ihnen auch gefallen