Hello Friends,
'Tis me again, with what might possibly be a very simple question, but one I just don't know where to start searching. I will begin with an example that should make sense to everyone, then describe what I am trying to do.
First, a common example. Let us say we are working with an object. An object has properties, some of which can be changed, and it also has methods which do things. For example, a Form has the Property of BackColor, which can be changed do different colors. But Forms also have the Method of MoveSize, which does something: it moves the form or changes the visual dimensions of the form, using values for the Top, Left, Height and Width arguments for that method. In VBA it might look something like this:
Super Simple!
Now, let's say, for example, that I have created a new class module that I have named Person:
Then, when we want to create a person:
Thus, I can manipulate this data all day long. I can also use other code to display the data in this Person:
Which will result in this being displayed in the Immediate Window:
So, finally, here is my question: Is there a way to add a Method to a Class, such that all I need to do is do this:
and that code will execute my Sub DisplayPerson?
Again, this may have a super simple answer--I just haven't been able to find any answers out there.
Thanks for the hepp!
'Tis me again, with what might possibly be a very simple question, but one I just don't know where to start searching. I will begin with an example that should make sense to everyone, then describe what I am trying to do.
First, a common example. Let us say we are working with an object. An object has properties, some of which can be changed, and it also has methods which do things. For example, a Form has the Property of BackColor, which can be changed do different colors. But Forms also have the Method of MoveSize, which does something: it moves the form or changes the visual dimensions of the form, using values for the Top, Left, Height and Width arguments for that method. In VBA it might look something like this:
Code:
Private Sub ChangeForm()
With Me
.BackColor = RGB(0, 0, 0)
Call .MoveSize(Top:=0, _
Left:=0, _
Height:=1296, _
Width:=1800)
End With
End Sub
Now, let's say, for example, that I have created a new class module that I have named Person:
Code:
Option Compare Database Option Explicit Public Name As String Public Height As Integer 'Height in Inches for US folks Public HairColor As String
Code:
Private Sub CreatePerson()
Dim perBlank As New Person
With perBlank
.Name = "Hulk Hogan"
.Height = 80
.HairColor = "Blonde"
End With
End Sub
Code:
Private Sub DisplayPerson()
Debug.Print perBlank.Name
End Sub
Hulk Hogan.So, finally, here is my question: Is there a way to add a Method to a Class, such that all I need to do is do this:
Code:
Call perBlank.Display
Again, this may have a super simple answer--I just haven't been able to find any answers out there.
Thanks for the hepp!
Comment