Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Monday 18 May 2015

Vb-Script Functions

Left Function: Returns left side of string from a given string
Dim Val, x,y
Val="Hyderabad"
x=Left(Val,3)
Msgbox x

Output: Hyd

Val=100
x=Left(Val,1)
Msgbox x

Output: '1

Val="Hyderabad"
x=Left(Val,0)
Msgbox x

Output: Null

Val="Hyderabad"
x=Left(Val,12)
Msgbox x

Output: Hyderabad

Val=#10-10-10#
x=Left(Val,3)
Msgbox x

Output: 10/

Val="Hyderabad"
x=Left(Val)
Msgbox x

Output: 'Error (Lengnth is Manditory)

Right Function: This function returns the right side of the string from the given string
Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".

Len Function: Returns the number of characters in a string or the number of bytes required to store a variable.
Dim Mystring
mystring=Len("G.C.Reddy")
msgbox mystring

Output: 9

Dim Mystring
Mystring=Inputbox("Enter a Value")
Mystring=Len(Mystring)

Msgbox Mystring

Mid Function: Returns a specified number of characters from a string.
Dim Val, x,y
Val="Hyderabad"
x=Mid(Val,3,4)
Msgbox x

Output:  dera

Val=100
x=Mid(Val,1)
Msgbox x

Output:  100

Val="Hyderabad"
x=Mid(Val,6,7)
Msgbox x

Output: abad

Val="Hyderabad"
x=Mid(Val,6,1)

Msgbox x

Output: a

Val="Hyderabad"
x=Mid(Val,6,0)

Msgbox x

Output: Null

Val="Hyderabad"
x=Mid(Val,12)
Msgbox x

Output: Null

Val=#10-10-10#
x=Mid(Val,3,3)
Msgbox x

Output: /10

Val=#2010-10-10#
x=Mid(Val,5)
Msgbox x

Output: /2010

Val="Hyderabad"
x=Mid(Val)
Msgbox x

Output: Error

Timer Function: Returns the number of seconds that have elapsed since 12:00 AM (midnight).
Function myTime(N)
Dim StartTime, EndTime
StartTime = Timer
For I = 1 To N
Next
EndTime = Timer
myTime= EndTime - StartTime
msgbox myTime
End Function

Call myTime(2000)

isNumeric Function : It Returns True/False  Result 
Dim MyVar, MyCheck
MyVar = 53
MyCheck = IsNumeric(MyVar)
msgbox MyCheck

MyVar = "459.95"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck

MyVar = "45 Help"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
RoundReturns a number rounded to a specified number of decimal places.
Dim num
num=172.499
num=Round(num)
msgbox num

OutPut: 172

StrReverse: It returns reverse value of the given sring
 x=strreverse ("dabaraedyh")
msgbox x

Output: hydearabad

strComp:It compares two strings based on ASCII Values and Returens -1 (1st less than 2nd ), 0 (Equal) and 1 (1st greater than 2nd)
Dim x, y
x="cd": y="bcd"
comp=strcomp(x,y)
msgbox comp

Output: 1
Replace: It replace a sub string with given value (another sub string)

 mystring=Replace("kb script""k","v")
msgbox mystring

Output: vb script


Abs Function: Returns the absolute value of a number.
Dim num
num=abs(-50.33)
msgbox num

Output: 50.33


Array Function: Returns a variant containing an Array
Dim A
A=Array("hyderabad","chennai","mumbai")
msgbox A(0)
ReDim A(5)
A(4)="nellore"
msgbox A(4)

Output 1: hyderabad; Output 2: nellore

Asc Function: Returns the ANSI character code corresponding to the first letter in a string.
Dim num
num=Asc("A")
msgbox num

OutPut:  65 

Chr Function: Returns the character associated with the specified ANSI character code.
Dim char
Char=Chr(65)
msgbox char

OutPut: A

CInt Function:Returns an expression that has been converted to a Variant of subtype Integer.
Dim num
num=123.45
myInt=CInt(num)
msgbox MyInt

Output: 123

6) Date Function: Returns the Current System Date.
Dim mydate
mydate=Date
msgbox mydate

Output: We get our system current date

7) Day Function: 
Dim myday
myday=Day("17,December,2009")
msgbox myday

Output: 17

Dim myday
mydate=date
myday=Day(Mydate)
msgbox myday

Output: We get current date

DateDiff Function: Returns the number of intervals between two dates.
Dim Date1, Date2, x
Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("yyyy", Date1, Date2)
Msgbox x 'Differnce in Years

Output:2

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("q", Date1, Date2)
Msgbox x 'Differnce in Quarters

Output: 8

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("m", Date1, Date2)
Msgbox x 'Differnce in Months

Output: 24

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("w", Date1, Date2)
Msgbox x 'Differnce in weeks

Output: 104

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("d", Date1, Date2)
Msgbox x 'Differnce in days

Output: 730

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("h", Date1, Date2)
Msgbox x 'Differnce in Hours

Output:17520

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("n", Date1, Date2)
Msgbox x 'Differnce in Minutes

Output: 1051200

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("s", Date1, Date2)
Msgbox x 'Differnce in Seconds

Output: 63072000

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("y", Date1, Date2)
Msgbox x  'Differnce in day of years

Output: 730

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("a", Date1, Date2)
Msgbox x 'Error

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff(Date1, Date2)
Msgbox x 'Error

Hour Function: Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
Dim mytime, Myhour
mytime=Now
myhour=hour(mytime)

msgbox myhour

Join Function: Returns a string created by joining a number of substrings contained in an array.
Dim mystring, myarray(3)
myarray(0)="Chandra "
myarray(1)="Mohan "
myarray(2)="Reddy"
mystring=Join(MyArray)
msgbox mystring

Output: Chandra Mohan Reddy

Eval Function: Evaluates an expression and returns the result.

Time Function: Returns a Variant of subtype Date indicating the current system time.
Dim mytime
mytime=Time
msgbox mytime

Output: we get current time of your system

VarType Function: Returns a value indicating the subtype of a variable.
Dim x,y
x=100
y=VarType(x)
Msgbox y

Output: 2 (Integer)
x="Hyderabad"
y=VarType(x)
Msgbox y

Output: '8 (String)
x=#10-10-10#
y=VarType(x)
Msgbox y

Output: 7(Date format)
x=100.56
y=VarType(x)
Msgbox y

Output:  5(Double)
y=VarType(a)
Msgbox y
Output: '0 (Empty)

Set x =CreateObject("Scripting.FileSystemObject")
y=VarType(x)
Msgbox y

Output: 9(Automation Object)

Inputbox Function: Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.

Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)

Input:UFT
Output: You entered UFT

Msgbox Function:Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.

Dim MyVar
MyVar = MsgBox ("Hello World!"65"MsgBox Example")

Output: Hello World!

CreateObject:creates and returns reference of the filesytemobject to an Automation object. It can be used for performing operations on computer file system

Set objFso=createobject ("Scripting.FileSystemObject")

'creates and returns reference of  the Excel object to an Automation object. It can be used for performing operations on Spreed sheet (Ms-Excel files)

Set objExcel = CreateObject("Excel.Application")

'creates and returns reference of  the Word Object to an Automation object. It can be used for performing operations on Ms-Word documents

Set objWord = CreateObject("Word.Application")

'creates and returns reference of  the Database Connection to an Automation object. It can be used for Connecting, opening and Closing databases

Set objConnection = CreateObject("ADODB.Connection")

'creates and returns reference of  the Database Recordset to an Automation object. It can be used for performing operations on database tables(Records)

Set objRecordSet = CreateObject("ADODB.Recordset")

'creates and returns reference of  the Ms-Power point object to an Automation object. It can be used for performing operations on Power point presentations

Set objPPT = CreateObject("PowerPoint.Application")

Set xmldoc = WScript.CreateObject("msxml2.domdocument")

No comments:

Post a Comment

Note: only a member of this blog may post a comment.