Class clsTestData
Private mDict
Public sWorkBook
Public vSheet
Public iRow
Public Default Function Load(sWorkBook, vSheet, iRow)
With Me
.sWorkBook = sWorkBook
.vSheet = vSheet
.iRow = iRow
End With
BuildContext : Set Load = oDict
End Function
Private Function BuildContext
Dim oConn, oRS, arrData, x
CONST adOpenStatic = 3
CONST adLockOptimistic = 3
CONST adCmdText = "&H0001"
Set oConn = CreateObject("ADODB.Connection")
Set oRS = CreateObject("ADODB.RecordSet")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=" & Me.sWorkBook & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
sQuery = "Select * From [" & Me.vSheet & "$]"
oRS.Open sQuery, oConn, 3, 3, 1
For x = 2 to iRow - 1 : oRS.MoveNext : Next
oDict = CreateObject("Scripting.Dictionary")
For x = 0 to oRS.Fields.Count - 1
With oDict
.Add "" & oRS(x).Name, "" & oRS.Fields(x)
End With
Next
End Function
Private Property Let oDict(ByVal Val)
Set mDict = Val
End Property
Private Property Get oDict()
Set oDict = mDict
End Property
End Class
Set mDataContext = New clsTestData
sWorkBook = "C:\Test.xls"
vSheet = "Sheet1"
iRow = 2
Set mDict = mDataContext.Load(sWorkBook, vSheet, iRow)
MsgBox mDict("Execute_Test")
MsgBox mDict("Scenario Name")
MsgBox mDict("Username")
MsgBox mDict("Password")
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set mDict ("Username")
Dialog("Login").WinEdit("Password:").Set mDict ("Password")
Dialog("Login").WinButton("OK").Click
Thanks for the useful information.
ReplyDeleteQTPbook