Demonstration script that combines the usage of classes and dictionary object. Script must be run on the local computer.
Class Employee
Private fname,lname,m_id,m_city,m_country
Public Property Get FirstName()
FirstName = fname
End Property
Public Property Let FirstName( value )
fname = value
End Property
Public Property Get LastName()
LastName = lname
End Property
Public Property Let LastName( value )
lname = value
End Property
Public Property Get Id()
Id = m_id
End Property
Public Property Let Id( value )
m_id = value
End Property
Public Property Get City()
City = m_city
End Property
Public Property Let City( value )
m_city = value
End Property
Public Property Get Country()
Country = m_country
End Property
Public Property Let Country( value )
m_country = value
End Property
End Class
Set listEmployee = CreateObject( "Scripting.Dictionary" )
listEmployee.Add "1", New Employee
listEmployee( "1" ).Id = "3425789734"
listEmployee( "1" ).FirstName = "Dani"
listEmployee( "1" ).LastName = "Vainstein"
listEmployee( "1" ).City = "Petaj Tikva"
listEmployee( "1" ).Country = "Israel"
listEmployee.Add "2", New Employee
listEmployee( "2" ).Id = "456875677"
listEmployee( "2" ).FirstName = "Sara"
listEmployee( "2" ).LastName = "Vainstein"
listEmployee( "2" ).City = "BatYam"
listEmployee( "2" ).Country = "Israel"
' ** Printing
For nEmp = 1 To listEmployee.Count
Print "Employee No: " & nEmp
Print listEmployee( Cstr( nEmp ) ).FirstName
Print listEmployee( Cstr( nEmp ) ).LastName
Print listEmployee( Cstr( nEmp ) ).Country
Next
Posted in Dictionary Objects


daniva




May 13th, 2008 at 10:50 am
I found this article is pretty useful for me to fully understand the concept of dictionary object and class.
But I found a problem, the code of “listEmployee.add “1″,New Employee” doesn’t work out at all in my QTP.I have to modify this code as below:
Set listEmployee=CreateObject(”Scripting.Dictionary”)
Set N_Employee=New Employee
N_Employee.ID=”123456″
listEmployee.add “1″, “123456″
N_Employee.FirstName=”Qing”
listEmployee.add “2″,”Qing”
N_Employee.LastName=”He”
listEmployee.add “3″, “He”
N_Employee.City=”Shanghai”
listEmployee.add “4″, “Shanghai”
N_Employee.Country=”China”
listEmployee.add “5″, “China”
For nEmp=1 To listEmployee.Count
Print “Employee Info:” & nEmp
Print listEmployee(Cstr(nEmp))
Next
I just wonder if the author could tell me the cause of this problem.
May 13th, 2008 at 11:29 pm
is hard to understand the term “your QTP”
i debugged the script, and it works find.
one issue might have a problem
QTP yelds syntax error on listEmployee.Add “1″, New Employee, yes maybe it’s that
but believe me is legal and is QTP erro . ignore it
June 15th, 2008 at 7:51 am
cool stuff.really helpful