devxlogo

Using Global Class Objects

Using Global Class Objects

Question:
I have a general class that has the following amongst other stuff.

Public Property Get Status() As String    Status = stattxtEnd PropertyPublic Property Let Status(vNewValue As String)    stattxt = vNewValueEnd Property
In the Mdi document I create a new instance of the class that this code is in I then have a timer event on the Mdi that monitors this value. I set the value to this property in child forms, but because I have to declare a new instance of the class in the child form my mdi document does not pick it up. How can I set the value in the child document without creating a new instance of the class object?

Answer:
You can instantiate the class in the MDI form like so:

Dim objClass as New CClass
But declare the objClass variable in a separate code module. Any variablesdeclared within a form, even if they are in the declarations section, arelocal to that form. You can’t share them across forms automatically. Theonly way to make it work is to put the variable declaration in a code module.

See also  lenso.ai - an AI reverse image search platform
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist