UFT Class 28
(VBScript Built in Functions part-2, Many to Many Comparisons Example)
28) CreateObject Function
It creates an automation object in a specified class.
Examples:
Dim objFso
‘Create File System Object, It is used to work with Drives, folders and files.
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Dim obJExcel
‘Create Excel Application object, It is used to perform operations on excel Application.
Set objExcel = CreateObject(“Excel.Application”)
‘Create Word Application Object, It is used to perform Operations on Word Application
Dim objWord
Set objeWord = CreateObject(“Word.Application”)
Dim objConnection
‘Create Database Connection Object, It is used to connect to Databases
Set objConnection = CreateObject(“Adodb.Connection”)
Dim objRecordset
‘Create Database Recordset object, It is used to perfom operations on Database Tables
Set objRecordset = CreateObject(“Adodb.Recordset”)
Dim objDictionary
‘Create Dictionary object, It is used to define key, value pairs.
Set objDictionary = CreateObject(“Scripting.Dictionary”)

29) Join Function
Dim a(3)
a(0) = “VB”
a(1) = “Script”
a(2) = “Language”
Msgbox Join(a) ‘VB Script Language
30) LBound Function
31) UBound Function
Dim a
a = Array(10, 20, 30, 40, 50, 60)
Msgbox IsArray(a) ‘True
Msgbox LBound(a) ‘0
Msgbox UBound (a) ‘5
32) InputBox Function
33) MsgBox Function
Dim val
val = InputBox(“Enter a Value”)
Msgbox “Value is: “& val
——————————–
Dim a, b
a =100
b = 200
Msgbox “Hello UFT”
Msgbox a
Msgbox “Addition of a, b is: “& a + b
Many to Many Comparisons Example using Nested for loop and Excel Objects.
Test Requirement:
Read items from a combo box /Drop down box and compare with Excel file data.
Actual: from “Fly From:” Combo box
Expected: from Excel file 1st sheet:
———————————
Dim objExcel, objWorkbook, objWorksheet, Actual, Expected, i, FlyFromCount
Set objExcel = CreateObject(“Excel.Application”)
Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\G C Reddy\Desktop\Input.xlsx”)
Set objWorksheet = objWorkbook.Worksheets(1)
RowsCount = objWorksheet.Usedrange.Rows.Count
Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).ActiveX(“MaskEdBox”).Type “111115”
FlyFromCount = Window(“Flight Reservation”).WinComboBox(“Fly From:”).GetItemsCount
For i = 0 To FlyFromCount-1 Step 1
Window(“Flight Reservation”).WinComboBox(“Fly From:”).Select(i)
objWorksheet.Cells(i+2, 2) = Window(“Flight Reservation”).WinComboBox(“Fly From:”).GetROProperty(“text”)
Next
Flag = 0
For j = 2 To RowsCount Step 1
Expected = objWorksheet.Cells(j, 1)
For k = 2 To RowsCount Step 1
Actual = objWorksheet.Cells(k, 2)
If StrComp(Expected, Actual, 1) = 0 Then
Flag = 1
Exit For
Else
Flag = 0
End If
Next
If Flag = 1 Then
objWorksheet.Cells(j, 3) = “Passed”
Else
objWorksheet.Cells(j, 3) = “Failed”
End If
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
————————————————
> Prepare Expected in Excel file (Sheet 1) 1st Column.
> Read Actual values from the Application Object and store into Excel file (Sheet 1) 2nd column.
> Read Expected and Actual values from Excel file using Nested for loop and compare (many to many comparisons)
Follow me on social media: