Micro Focus QTP (UFT) Forums
trouble with Class statement / user defined objects - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: trouble with Class statement / user defined objects (/Thread-trouble-with-Class-statement-user-defined-objects)



trouble with Class statement / user defined objects - mknapp_qa - 08-14-2008

I'm using a Class statement (follows at end) that i'd like to locate outside of the main test, in order to reuse it easier.

If i include the entire statement in the main action, it works fine.

If i do any of the following, i get "class undefined" error when trying to create an instance of it (via: Set shopper = new User):

1. create a new test called "Classes". Create a reusable action in it called
"UserClass", which contains the Class statement. Call it either via "include call to external action" or "insert copy of existing action".

2. create function library called UserClass.qfl.
Include the Class statement in this qfl, surrounded by:

Sub makeUserClass()
[Class statement]
End Sub

I associate the qfl with the test, then call makeUserClass() before creating new instance.

3. save Class statement variously as UserClass.qfl, UserClass.vbs, User.class. variously use: executeFile; executeGlobal (on a string containing the code).


Code:
Class User
   dim email,_
    fname,_
    lname,_
    ....etc

    Sub Class_Initialize()
        email = "qa" & MonthName(Month(Now)) &_
                   Day(Now) & Year(Now) & Hour(Now) &_
                   Minute(Now)& Second(Now) & "@mydomain.com"
        fname = RandomWord(3,10)
        lname = RandomWord(3,10)
        ....etc        
    end sub

    Sub saveUser()
        DataTable.Value("email", "Global") = email
        DataTable.Value("fname", "Global") = fname
        DataTable.Value("lname", "Global") = lname
        ....etc
    end sub  
End Class



any help on how to clean this up appreciated.

mike

(QTP 9.2)