-1

I have vbs files and associated with UFT. The libraries are loaded and class object is initialized successfully.

But when it comes to execute Class Method in QTP action, it does not recognized the class object and message says method is not supported. When I checked the value it says Object and have no refrence to Class.

Please help me on this.

Thanks, dev

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73

1 Answers1

0

If your class is inside a library and you are calling it from the test (action), you will receive this error. You haven't shared how you have instantiated your class, but here are 2 ways you can do so:

Class MyClass
    Public Sub MyMethod()
        MsgBox "MyMethod called"
    End Sub
End Class

' 1:
Public oMyClass
Set oMyClass = New MyClass

' 2: 
Public Function MyFunc()
    Set MyFunc = New MyClass
End Function

This is how you can use the above 2 approaches in your action:

' 1:
oMyClass.MyMethod

' 2:
MyFunc.MyMethod

A major difference between these 2 approaches is that the function() approach will create a new instance everytime it is used. The variable usage will create and hold the same instance (unless you create it again).

Anshoo
  • 725
  • 5
  • 10
  • Thanks for replying Anshoo. What i did is initialized object in library itself like in your example. If i put oMyClass.MyMethod in same library, its get executed perfectly but if same i put in Action , it say MyClass.MyMethod is not defined. – devkumar314 Feb 13 '15 at 05:18
  • That´s why you must use the approach #2. You cannot reference the class name outside of the library. I.e. class definitions are always `private`. So in the library, you need to create a public creator (factory) function as shown. Call that one in the main action, like in `Dim B: Set B=MyFunc`. By keeping the reference you can use `B` like you would use `oMyClass` (i.e. without getting a new instance). – TheBlastOne Feb 13 '15 at 10:49
  • Thanks for the suggestion. I think i got the solution. Something broken in UFT 12.2 thats why its not calling like that. I had UFT 12.0 now and my code works fine. Thanks for your feedback, will keep this for future. – devkumar314 Feb 16 '15 at 05:42