vb script operators

5

Click here to load reader

Upload: gcreddy

Post on 30-May-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: VB Script Operators

8/9/2019 VB Script Operators

http://slidepdf.com/reader/full/vb-script-operators 1/5

[email protected]

Visit:

http://www.gcreddy.com

For VB Script and QTP Info

VB Script Operators

Operator precedence

a=10+20*2

msgbox a '50

a=(10+20)*2msgbox a '60

1) Arithmetic

a) ^ Exponentiation

b) * multiplication

c) / division

d) \ Integer division

e) Mod operator

f) + Addition

g) - subtraction

h) & concatenation

Example:Dim a,b,c

a=10b=3c=a^b

msgbox c '1000

c=a*bmsgbox c '30

www.gcreddy.com 1

Page 2: VB Script Operators

8/9/2019 VB Script Operators

http://slidepdf.com/reader/full/vb-script-operators 2/5

[email protected]

c=a/bmsgbox c '3.33333333

c=a\bmsgbox c '3

c=a mod bmsgbox c '1

c=a-b

msgbox c '7

Dim a,b,ca=10

b=2c=3

d=c*a^b

'c=a+bmsgbox d '1000

Addition (+) operator

Dim a,b,ca=10

b=2c=a+b

msgbox c '12 (if both are numeric, then it adds)

a="10"b=2c=a+bmsgbox c '12 (one is string another numeric, then it adds)

a="10"

b="2"c=a+b

msgbox c '102 (if both are strings, then it concatenates)

a="hydera"b="bad"

c=a+bmsgbox c 'hyderabad

a="gagan"

b=2c=a+bmsgbox c 'error

www.gcreddy.com 2

Page 3: VB Script Operators

8/9/2019 VB Script Operators

http://slidepdf.com/reader/full/vb-script-operators 3/5

[email protected]

Concatenation OperatorDim a,b,c

a=10b=2c=a&bmsgbox c '102

a="10"

b=2c=a&b

msgbox c '102

a="10"b="2"

c=a&bmsgbox c '102

a="hydera"b="bad"c=a&b

msgbox c '102

2) Comparison Operators (have equal precedence)a) =

b) <c) <=

d) >e) >=

f) <>

Example:Dim a,b,c

a=10b=2

c=a=bmsgbox c 'false

c=a<bmsgbox c 'false

c=a>bmsgbox c 'true

3) Logical (have equal precedence)

a) Not (Logical Negation)

www.gcreddy.com 3

Page 4: VB Script Operators

8/9/2019 VB Script Operators

http://slidepdf.com/reader/full/vb-script-operators 4/5

[email protected]

If not window("Flight Reservation").Exist (3) Then

SystemUtil.Run "D:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe","","D:\ProgramFiles\HP\QuickTest Professional\samples\flight\app\","open"Dialog("Login").Activate

Dialog("Login").WinEdit("Agent Name:").Set "fsdfsf"Dialog("Login").WinEdit("Password:").SetSecure

"4bda42ce3f38c716e0de9aadc2cdb242d58a0d1d"Dialog("Login").WinButton("OK").Click

End If For ord= 1 to 5Window("Flight Reservation").ActivateWindow("Flight Reservation").WinButton("Button").Click

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("OrderNo.").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").ClickNext

b) and (Logical conjunction)

Exp 1 Exp2 ResultTrue True True

True False FalseFalse True False

False False False

Dim a,b,ca=100:b=20:c=30If a>c and a>b Then

msgbox "a is a big number"

elsemsgbox "a is Not a big number"

End If 

c) or (Logical disjunction)

Exp 1 Exp2 ResultTrue True True

True False TrueFalse True True

False False False

d) xor (Logical exclution)

Exp 1 Exp2 ResultTrue True False

www.gcreddy.com 4

Page 5: VB Script Operators

8/9/2019 VB Script Operators

http://slidepdf.com/reader/full/vb-script-operators 5/5

[email protected]

True False TrueFalse True True

False False False

www.gcreddy.com 5