devxlogo

Accessing Properties

Accessing Properties

Question:
How do you access a Public Property in a class module from an in-project module? For example:In a new project create one class module; “Class1” and one bas module; “Module1”, with the following code:Class1:

Public Property Get Test() As Integer    Test = 99End Property
Module1:
Public Sub Main()    Debug.Print {Class1.Test}  ‘ This is where we want to                                ‘ get the info from Class1End Sub
What is necessary to retrieve the property value from Class1 within other parts of the application??????

Answer:
You’ve basically got it, except you need to instantiate (create) an object of class “Class1”. Do that like this:

Dim aClass1 as Class1Set aClass1 = New Class1
Then you can print Test with:
Debug.Print aClass1.Test

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
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