Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Sunday, November 28, 2010

VB Script Built-in functions

VB Script Built-in functions


1) Asc Function


Dim Val
val=”A”
Msgbox Asc(val) ’65
Msgbox Asc(“Z”) ’90
Msgbox Asc(“a”) ’97
Msgbox Asc(“z”) ’122
Msgbox Asc(1) ’49
Msgbox Asc(“*”) ’42

Msgbox Asc(“America”) ’65

2) Chr Function

Dim Val
val=65
Msgbox Chr(val) ‘A
Msgbox Chr(90) ‘Z
Msgbox Chr(97) ‘a
Msgbox Chr(122) ‘z
Msgbox Chr(49) ’1
Msgbox Chr(42) ‘*

3) Abs Function

Dim Val
val=65.45
Msgbox Abs(val) ’65.45

val=65.55
Msgbox Abs(val) ’65.55

val=-65.55
Msgbox Abs(val) ’65.55

4) Round Function

Dim Val
val=65.45
Msgbox Round(val) ’65

val=65.55
Msgbox Round(val) ’66

val=-65.55
Msgbox Round(val) ‘-66
val=65.50
Msgbox Round(val) ’66

5) Array Function

Dim x
x=Array(“Hyderabad”, “Chennai”,”Deldhi”)
Msgbox x(0)
Msgbox x(1)
Msgbox x(2)

x=Array(100,200,300)
Msgbox x(0)
Msgbox x(1)
Msgbox x(2)

x=Array(#10-10-10#, #10/10/10#,#10/10/2010#,#Sep-10-10#)
Msgbox x(0)
Msgbox x(1)
Msgbox x(2)
Msgbox x(3)

x=Array(“Hyderabad”, 100,#10/10/2010#)
Msgbox x(0)
Msgbox x(1)
Msgbox x(2)

6) IsArray Function

Dim a,b,c(3),d(),e(2,3)
Msgbox IsArray(a) ‘False
Msgbox IsArray(b) ‘False
Msgbox IsArray(c) ‘True
Msgbox IsArray(d) ‘True
Msgbox IsArray(e) ‘True

a=Array(100,200,300)
Msgbox IsArray(a) ‘True
b=Split(“VB Script Language”,” “)
Msgbox IsArray(b) ‘True

Msgbox b(0)
Msgbox b(1)
Msgbox b(2)

7) IsDate Function

Dim val
val=”Hyderabad”
Msgbox IsDate(val) ‘False

val=100
Msgbox IsDate(val) ‘False

val=100.45
Msgbox IsDate(val) ‘False

val=#10-10-10#
Msgbox IsDate(val) ‘True

val=#10/10/10#
Msgbox IsDate(val) ‘True

val=#10-10-2010#
Msgbox IsDate(val) ‘True

val=#October-10-10#
Msgbox IsDate(val) ‘True

  Date Function

Dim myDate
myDate=Date
Msgbox myDate

9) Time Function

Dim myTime
myTime=Time
Msgbox myTime

10) Now Function

Dim myDay
myDay=Now
Msgbox myDay

myDay=Date & Time
Msgbox myDay

myDay=Time & Date
Msgbox myDay

11) Len Function

Dim val
val=”Hyderabad”
Msgbox Len(val) ’9

Msgbox Len(100) ’3

Msgbox Len(“@#$%^”) ’5

Msgbox Len(#10-10-2010#) ’10

Msgbox Len(#10-10-10#) ’10

Msgbox Len(#Sep-10-2010#) ’9

Msgbox Len(#Nov-10-2010#) ’10

Msgbox Len(Hyderabad) ’0

12) Left Function

Dim val
val=”Hyderabad”
Msgbox Left(val,3) ‘Hyd

Msgbox Left(100,2) ’10

Msgbox Left(#10-10-10#,5) ’10/10

Msgbox Left(“#10-10-10#”,3) ‘#10
—————–
Example:
Model 1:
Read a Mobile Number and verify the Series
‘Val should be Numeric
‘Val should contain 10 digits
‘If series is either “92478? or “92471 then display Tata Indicom Number
‘If series is either “98490? or “98480 then display AirTel Number

Dim val, val_Length, val_Numeric, val_Series
val=InputBox(“Enter a Mobile Number”)
val_Numeric=IsNumeric(val)
val_Length=Len(val)
val_Series=Left(val,5)

If val_Numeric=True and  val_Length=10 and val_Series=92478 Or  val_Series=92471  Then
Msgbox “It is a Tata Indicom Number”
ElseIf val_Numeric=True and  val_Length=10 and val_Series=98490 Or  val_Series=98480   Then
Msgbox “It is an Air Tel  Number”
Else
Msgbox “Invalid Data”
End If
—————————-
2nd Model:
‘Read a Mobile Number and verify the Series
‘Val should be Numeric
‘Val should contain 10 digits
‘If series is either “92478? or “92471 then display Tata Indicom Number
‘If series is either “98490? or “98480 then display AirTel Number

Dim val, val_Length, val_Numeric, val_Series
val=InputBox(“Enter a Mobile Number”)
val_Numeric=IsNumeric(val)
val_Length=Len(val)
val_Series=Left(val,5)
If  val_Numeric= True Then
If val_Length=10 Then
If val_Series=92478 Or  val_Series=92471  Then
Msgbox “It is a Tata Indicom Number”
ElseIf val_Series=98490 Or val_Series=98480  Then
Msgbox “It is an Air Tel  Number”
Else
Msgbox “Invalid Series”
End If

Else
Msgbox “It is not a 10 digit value”
End If
Else
Msgbox “It is not a Numeric Value”
End If

13) Right Function

Dim val
val=”Hyderabad”
Msgbox Right(val,3) ‘bad

Msgbox Right(100,2) ’00

Msgbox Right(#10-10-10#,5) ‘/2010

Msgbox Right(“#10-10-10#”,3) ’10#

val=”Hyderabad”
Msgbox Right(val,9) ‘Hyderabad

val=”Hyderabad”
Msgbox Right(val,20) ‘Hyderabad

val=”Hyderabad”
Msgbox Right(val,0) ‘Blank

val=”Hyderabad”
Msgbox Right(val) ‘Error (Length is Maditory)

14) Mid Function

Dim val
val=”Hyderabad”
Msgbox Mid(val,5,3) ‘rab

Msgbox Mid(100,2) ’00

Msgbox Mid(#10-10-10#,5) ’0/2010

Msgbox Mid(“#10-10-10#”,3,3) ’0-1

val=”Hyderabad”
Msgbox Mid(val,9) ‘d

val=”Hyderabad”
Msgbox Mid(val,20) ‘Blank

val=”Hyderabad”
Msgbox Mid(val,0) ‘Error

val=”Hyderabad”
Msgbox Mid(val) ‘Error
————-
Ex:
Price=”$100.45?
Units=”5?
Total=Units*Price
Msgbox Total

Price=”Rs100.45?
Price=Mid(Price,3)
‘Price=Right(Price,6)
Units=”5?
Total=Units*Price
Msgbox Total

15) DateDiff Function

Dim date1, date2

date1=#10-10-11#
date2=#10-10-09#
Msgbox DateDiff(“d”,date1,date2) &” Days”

date1=#10-10-09#
date2=#10-10-11#

Msgbox DateDiff(“d”,date1,date2) &” Days”

Msgbox DateDiff(“m”,date1,date2) &” Months”

Msgbox DateDiff(“yyyy”,date1,date2) &” Years”

Msgbox DateDiff(“w”,date1,date2) &” Weeks”

Msgbox DateDiff(“h”,date1,date2) &” Hours”

Msgbox DateDiff(“n”,date1,date2) &” Minutes”

Msgbox DateDiff(“s”,date1,date2) &” Seconds”

Msgbox DateDiff(“q”,date1,date2) &” Quarters”

16) Timer Function

Start_Transaction=Timer
SystemUtil.Run “C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”
Dialog(“Login”).Move 356,281
Dialog(“Login”).WinEdit(“Agent Name:”).Set “Thirupathi”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4cad3fd62c9fe96eebb24fc6c977a8a1e4fd28f4?
Dialog(“Login”).WinButton(“OK”).Click
Window(“Flight Reservation”).Activate
End_Transaction=Timer
Transaction_Time=End_Transaction-Start_Transaction
Msgbox Transaction_Time

17) StrComp Function

Dim str1, str2
str1=”HYDERABAD”
str2=”hyderabad”
Msgbox strComp(str1,str2) ‘-1 (str1<str2)

Msgbox strComp(str1,str2,0) ‘-1 (str1<str2) **0 is Compare mode for Binary

Msgbox strComp(str1,str2,1) ’0(str1<str2) **1 is Compare mode for Textual

str1=”hyd”
str2=”Hyderabad”
Msgbox strComp(str1,str2) ’1(str1<str2)

18) LCase Function

Dim Val
Val=”HYDERABAD”
Msgbox Lcase(val) ‘hyderabad

Val=”HyderabaD”
Msgbox Lcase(val) ‘hyderabad

Val=”hyderabad”
Msgbox Lcase(val) ‘hyderabad

Val=100
Msgbox Lcase(val) ’100

Val=”HYDERA100?
Msgbox Lcase(val) ‘hydera100

Val=”HYDER@#*”
Msgbox Lcase(val) ‘hyder@#*

19) UCase Function

Dim Val
Val=”HYDERABAD”
Msgbox UCase(val) ‘HYDERABAD

Val=”HyderabaD”
Msgbox UCase(val) ‘HYDERABAD

Val=”hyderabad”
Msgbox UCase(val) ‘HYDERABAD

Val=100
Msgbox UCase(val) ’100

Val=”HYDERA100?
Msgbox UCase(val) ‘HYDERA100

Val=”HYDER@#*”
Msgbox UCase(val) ‘HYDER@#*

20) Trim Function

21) RTrim Function

22) LTrim Function

Dim val
val=”                     VB Script                            ”
Msgbox val
Msgbox Trim(val)

val=”                     VB Script                            ”
Msgbox val
Msgbox RTrim(val)
val=”                     VB Script                            ”
Msgbox val
Msgbox LTrim(val)

23) CreateObject Function

Dim objFso
Msgbox VarType(objFso) ’0 for Empty
‘Creating an Automation Object in FileSystem Class, that can be used to perform File System Operations
Set objFso=CreateObject(“Scripting.FileSystemObject”)
Msgbox VarType(objFso) ’9 for Automation Object

Dim objExcel
‘Creating an Automation Object in Excel Class, that can be used to perform Spread sheet(Excel file)  Operations
Set objExcel=CreateObject(“Excel.Application”)

Dim objWord
‘Creating an Automation Object in Word Class, that can be used to perform Word Document Operations
Set objWord=CreateObject(“Word.Application”)

Dim objCon
‘Creating an Automation Object in Database Connection Class, that can be used to Connect to various databases
Set objCon=CreateObject(“Adodb.Connection”)

Dim objRs
‘Creating an Automation Object in Database RecordSet Class, that can be used to perform Operations on Database Tables(Records)
Set objRs=CreateObject(“Adodb.RecordSet”)

Dim objCom
‘Creating an Automation Object in Database CommandClass, that can be used to perform Maniplations on Databases
Set objCom=CreateObject(“Adodb.Command”)

Dim objDict
‘Creating an Automation Object in Dictionary class, that can be used to store “Key”, “Value” Pairs
Set objDict=CreateObject(“Scripting.Dictionary”)

24) IsEmpty Function


Dim x,y

x=100

Msgbox IsEmpty(x) ‘False

Msgbox IsEmpty(y) ‘True

y=”abcd”

Msgbox IsEmpty(y) ‘False


y=0

Msgbox IsEmpty(y) ‘False


y=Empty

Msgbox IsEmpty(y) ‘True

25) Cdbl Function


Dim val

val=”100.45?

Msgbox VarType(val) ’8 for String


val=Cdbl(val)

Msgbox VarType(val) ’5 for Double


26) CInt Function

Dim val

val=”100?

Msgbox VarType(val) ’8 for String


val=CInt (val)

Msgbox VarType(val) ’2 for Integer


val=”100.45?

Msgbox VarType(val) ’8 for String

Msgbox val


val=CInt (val)

Msgbox VarType(val) ’2 for Integer

Msgbox val


27) VarType Function


Dim val, x

val=”Hyderabad”

Msgbox VarType(val) ’8 for String


val=”100?

Msgbox VarType(val) ’8 for String


val=”100.456?

Msgbox VarType(val) ’8 for String


val=100

Msgbox VarType(val) ’2 for Integer


val=100.456

Msgbox VarType(val) ’5 for Double


Msgbox VarType(x) ’0 for Uninitialized


Msgbox VarType(#10/10/2010#) ’7 for Date format


Set x=CreateObject(“Scripting.FileSystemObject”)

Msgbox VarType(x) ’9 for Automation Object

0 comments:

Post a Comment

Loading...