About HP UFT 11.5 and it's features, watch the excellent video
For more information visit: http://www.hp.com/go/uft - HP Unified Functional Testing (UFT) 11.5 product movie, the new generation of functional testing by HP.
Automation Testing with QTP (Quick Test Professional), HP QTP, HP UFT, HP Unified Functional Testing
Function GetScrollBarState(ByRef document, ByVal scrollbarDir)
Dim result
Dim root
On Error Resume Next
Select Case LCase(document.compatMode)
Case "backcompat"
Set root = document.body
Case Else
Set root = document.documentElement
End Select
Select Case LCase(scrollbarDir)
Case "h"
scrollbarDir = "horizontal"
result = (root.scrollWidth > root.clientWidth)
Case "v"
scrollbarDir = "vertical"
result = (root.scrollHeight > root.clientHeight)
End Select
If Err.Number <> 0 Then
Reporter.ReportEvent micWarning, "GetScrollBarState", "Could not get state for " & scrollbarDir & " scrollbar"
result = "Undefined"
Err.Clear
End If
GetScrollBarState = result
End Function
The following two functions will be used as Page properties using QTP/UFT RegisterUserFunc:
Function HasHorizontalScrollbar(ByRef oPage)
HasHorizontalScrollbar = GetScrollBarState(oPage.Object, "h")
End Function
Function HasVerticalScrollbar(ByRef oPage)
HasVerticalScrollbar = GetScrollBarState(oPage.Object, "v")
End Function
RegisterUserFunc "Page", "HasHorizontalScrollbar", "HasHorizontalScrollbar"
RegisterUserFunc "Page", "HasVerticalScrollbar", "HasVerticalScrollbar"
'Usage with QTP/VBScript Code
Set oPage = Browser("Browser").Page("Page")
Print oPage.HasHorizontalScrollbar
Print oPage.HasVerticalScrollbar

Dim intIndex
Set oDesc=Description.Create
oDesc("micclass").Value="Browser"
intIndex=0
While Browser("micclass:=Browser","index:="&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
else
intIndex=intIndex+1
End if
wend
Using the below script, we will be able to search a particular value in the excel file.
*******************************************************************************************
Set appExcel = CreateObject("Excel.Application")
appExcel.visible=true
Set objWorkBook = appExcel.Workbooks.Open (filepath) 'opens the sheet
Set objSheet = appExcel.Sheets("Sheet1″)' To select particular sheet
With objSheet.UsedRange ' select the used range in particular sheet
Set c = .Find ("nn")' data to find
For each c in objSheet.UsedRange' Loop through the used range
If c="nn" then' compare with the expected data
c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
Set c = .FindNext(c)' next search
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing
**********************************************************************************************
Below are the some of the very important functions using the regular expression in VB Script, which will make your Automation script creation very easy.
"********************************************************************************************
"'Function to check if a string matches a Regular Expression Pattern
"********************************************************************************************
Function IsRegExMatch(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
'Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
IsRegExMatch = oRegExp.Test(strText)
Set oRegExp = Nothing
End Function
"********************************************************************************************
"'Function to Match a Regular Expression and Replace with a particular text if a string matches a regular expression pattern.
"********************************************************************************************
Function RegExMatchandReplace(strText,regEx_Pattern,strReplacementText,blnMatchCompleteString)
Dim oRegExp, retVal,strReplacedText
' Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
RegExMatch = oRegExp.Test(strText)
If RegExMatch = True Then
strReplacedText = oRegExp.Replace(strText,strReplacementText)
End If
RegExMatchandReplace = strReplacedText
Set oRegExp = Nothing
End Function
"********************************************************************************************
"'Function to Get Total Number of Matches of a Regular Expression Pattern in a particular string
"********************************************************************************************
Function GetRegExMatchCount(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
'Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
RegExpMatch = oRegExp.Test(strText)
If RegExpMatch Then
Set oRegExMatchCount = oRegExp.Execute(strText)
GetRegExMatchCount = oRegExMatchCount.Count
End If
Set oRegExp = Nothing
End Function
"********************************************************************************************
"'Function to Trim white space characters from end of a string
"********************************************************************************************
Public Function RTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a space character
RTrimPattern = "[\s]*$"
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern =RTrimPattern
oRegExp.Global = False
RTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function
"********************************************************************************************
"'Function to Trim white space characters from start of a string
"********************************************************************************************
Public Function LTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a space character
LTrimPattern = "^[\s]*"
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern = LTrimPattern
oRegExp.Global = False
LTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function
"********************************************************************************************
"Function to Trim white space characters from both start and end of a string
"********************************************************************************************
Public Function TrimW(ByVal Text)
TrimW = LTrimW(RTrimW(Text))
End Function
"********************************************************************************************
Return Value
|
SubDatatype
|
Description
|
0
|
vbEmpty
|
Empty (uninitialized)
|
1
|
vbNull
|
Null (no valid data)
|
2
|
vbInteger
|
Integer
|
3
|
vbLong
|
Long integer
|
4
|
vbSingle
|
Single-precision floating-point number
|
5
|
vbDouble
|
Double-precision floating-point number
|
6
|
vbCurrency
|
Currency
|
7
|
vbDate
|
Date
|
8
|
vbString
|
String
|
9
|
vbObject
|
Automation object
|
10
|
vbError
|
Error
|
11
|
vbBoolean
|
Boolean
|
12
|
vbVariant
|
Variant (used only with arrays of Variants)
|
13
|
vbDataObject
|
A data-access object
|
17
|
vbByte
|
Byte
|
8192
|
vbArray
|
Array
|
SubDatatype
|
Description
|
Byte
|
Byte value
|
Integer
|
Integer value
|
Long
|
Long integer value
|
Single
|
Single-precision floating-point value
|
Double
|
Double-precision floating-point value
|
Currency
|
Currency value
|
Decimal
|
Decimal value
|
Date
|
Date or time value
|
String
|
Character string value
|
Boolean
|
Boolean value; True or False
|
Empty
|
Unitialized
|
Null
|
No valid data
|
< object type >
|
Actual type name of an object
|
Object
|
Generic object
|
Unknown
|
Unknown object type
|
Nothing
|
Object variable that doesn't yet refer to an object instance
|
Error
|
Error
|