Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Useful VB Script Functions for QTP - String, Date, Array and Control flows

String Function:


Len: Returns the number of characters in a string or the number of bytes required to store a variable. 

Len(str)    
   

LCase:  Returns a string that has been converted to lowercase.


Ucase:  Returns a string that has been converted to uppercase.


Left: Returns a specified number of characters from the left side of a string.

Left(str,Length)

Right: Returns a specified number of characters from the right side of a string.

Right(str,Length)

Mid: Returns a specified number of characters from a string.

Mid(txt,start,[length])

Replace: Replaces string with another string

Replace(expression, find, replacewith[, start[, count[, compare]]])

Space: Returns a string consisting of the specified number of spaces.

Space (number)

Split: Returns a zero-based, one-dimensional array containing a specified number of substrings.

Split(expression[,delimiter[,count[,compare]]])

StrComp: Returns a value indicating the result of a string comparison. 

StrComp(string1,string2[,compare])

StrReverse: Returns a string in which the character order of a specified string is reversed.

strReverse(string)

LTrim; RTrim; and Trim: Returns a copy of a string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim).

Trim(str)
LTrim(str)
RTrim(str)

InStr: Returns the position of the first occurrence of one string within another.

InStr([start,]string1,string2[,compare])

InStrRev: Returns the position of an occurrence of one string within another, from the end of string. 

InStrRev(string1,string2[,start[,compare]])

Array Functions:


IsArray: Returns a Boolean value indicating whether a variable is an array.

IsArray(variable)

UBound: Returns the largest available subscript for the indicated dimension of an array.

UBound(arrayname[,dimension])

Join - The Join function returns a string that consists of a number of substrings in an array.

Join(list[,delimiter])


Date Functions:

Date: Returns the current system date.

Time: Returns a Variant of subtype Date indicating the current system time.


DateAdd: Returns a date to which a specified time interval has been added. 

DateAdd (interval, number, date): internal can be ‘yyyy’, ‘dd’,’mm’


DateDiff: Returns the number of intervals between two dates. 

DateDiff("yyyy","September 01, 2012","September 01, 2010")



DatePart: Returns the specified part of a given date. 

DatePart("yyyy","May 01, 2012") 


Day: Returns a whole number between 1 and 31, inclusive, representing the day of the month. Day(date)


Month: Returns a whole number between 1 and 12, inclusive, representing the month of the year.


MonthName: Returns a string indicating the specified month.


Weekday: Returns a whole number representing the day of the week.  

Weekday ("November 03, 2010") 


WeekdayName: Returns a string indicating the specified day of the week. 

WeekdayName (4)


Year: Returns a whole number representing the year.


Hour: Returns a whole number between 0 and 23, inclusive, representing the hour of the day


Minute: Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.


Second: Returns a whole number between 0 and 59, inclusive, representing the second of the minute. 


Now: Returns the current date and time according to the setting of your computer's system date and time.


Control Flows:

Do...Loop: Repeats a block of statements while a condition is True or until a condition becomes True.


For...Next Statement: For...Next: Repeats a group of statements a specified number of times.


For Each...Next: Repeats a group of statements for each element in an array or collection.


If...Then...Else: Conditionally executes a group of statements, depending on the value of an expression.


Select Case: Executes one of several groups of statements, depending on the value of an expression.


While...Wend: Executes a series of statements as long as a given condition is True.


With: Executes a series of statements on a single object.


No comments:

Post a Comment