Forum Discussion

elyush's avatar
elyush
Occasional Contributor
14 years ago

How declare class in one unit and create class object in other unit...?

Hi,

I am using TestComplete7, wrritng code  in VBScript. an i hav such problem.



I have declare class in unit A - class MyClass

                                                    'properties and methods

                                                End Class



And then in unit B i want to  create instance of MyClass such way-  set myinstance = new MyClass.

In unit B i include unit A .

When the script run,   throws exception - "Class not defined: MyClass"

Can't i  create object instance in other unit???

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Elya,



    In unit A you should create a function that returns an instance of the class and call this function from unit B.

    E.g.

    ' unit A

    Function InitClass()

      Set InitClass = new MyClass

    End Function



    class MyClass

      'properties and methods

    End Class





    'unit B

    ...

    Set vClass = Function InitClass()

    vClass.Property = ...

    intResult = vClass.Function(...)

    ...
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Oops...



    Obviously instead of

    'unit B

    ...

    Set vClass = Function InitClass()



    it had to be

    'unit B

    ...

    Set vClass = InitClass() ' copy-pasted 'Function' is not needed here



    Sorry for the typo...