Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Question: "myself" in a Class

Hello

I am working with classes and I have a little question: how do you
create a pointer on the object in which the procedure sits?

More precisely, I have an object A, which has a procedure that allows
to create some Objects B. This procedure gets a pointer on object B
each time it creates one. It is therefore easy to have a list of
pointer to B stored in A.

Now I would like to create a link the other way round. I would like to
store in B a pointer to object A. Ideally that would be done when I
create B in the procedure. But for that, I need in the definition of
the procedure (which sits in object A) to use a pointer on A. Is there
a sort of "myself" instruction that I can use for that?

Not sure if this is clear. Thanks in advance

Best regards
Charles

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Question: "myself" in a Class

I don't know is this is what you mean

Class1

Public test
Private mClass2 As Class2

Private Sub Class_Initialize()
test = "Testing initial class"
Set mClass2 = New Class2
mClass2.BackPointer = Me
mClass2.BackCall
End Sub

Class2

Private mBackClass As Object

Public Property Let BackPointer(ByRef Class As Object)
Set mBackClass = Class
End Property

Public Function BackCall()
MsgBox mBackClass.test
End Function


and test like so

Dim TestClass As Class1
Set TestClass = New Class1


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Charles" wrote in message
oups.com...
Hello

I am working with classes and I have a little question: how do you
create a pointer on the object in which the procedure sits?

More precisely, I have an object A, which has a procedure that allows
to create some Objects B. This procedure gets a pointer on object B
each time it creates one. It is therefore easy to have a list of
pointer to B stored in A.

Now I would like to create a link the other way round. I would like to
store in B a pointer to object A. Ideally that would be done when I
create B in the procedure. But for that, I need in the definition of
the procedure (which sits in object A) to use a pointer on A. Is there
a sort of "myself" instruction that I can use for that?

Not sure if this is clear. Thanks in advance

Best regards
Charles



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Question: "myself" in a Class

It works perfectly. That's exactly what I was looking for. "Me".....

Many thanks!
Charles

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Question: "myself" in a Class

"Me" is the reference to the current instance of the class. Something like
this

----- ClassA ----------
Private mstrName As String

Public Property Get Name()
Name = mstrName
End Property

Public Sub test()
Dim objB As New ClassB

mstrName = "ClassA"
Set objB.Parent = Me
MsgBox objB.Parent.Name

End Sub

----- ClassB ----------
Private mParent As ClassA

Public Property Set Parent(obj As ClassA)
Set mParent = obj
End Property

Public Property Get Parent()
Set Parent = mParent
End Property


----- Module1 ----------
Sub test()
Dim objA As New ClassA
objA.test
End Sub




--
Hope that helps.

Vergel Adriano


"Charles" wrote:

Hello

I am working with classes and I have a little question: how do you
create a pointer on the object in which the procedure sits?

More precisely, I have an object A, which has a procedure that allows
to create some Objects B. This procedure gets a pointer on object B
each time it creates one. It is therefore easy to have a list of
pointer to B stored in A.

Now I would like to create a link the other way round. I would like to
store in B a pointer to object A. Ideally that would be done when I
create B in the procedure. But for that, I need in the definition of
the procedure (which sits in object A) to use a pointer on A. Is there
a sort of "myself" instruction that I can use for that?

Not sure if this is clear. Thanks in advance

Best regards
Charles


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I make a "tab name" the "chart title"? (question on this) [email protected] Charts and Charting in Excel 2 April 15th 09 06:26 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Disk is Full" add-on question to "Can't reset last cell" post tod [email protected] Excel Discussion (Misc queries) 0 January 22nd 07 02:32 AM
Question on determining "ROW" inside of a "For .. RANGE " loop David Schrader[_2_] Excel Programming 2 January 3rd 07 08:18 PM
Validation question - allow -500%, 0%, "=50%*50%" but forbid "A", "", " ", "-" ? tskogstrom Excel Programming 2 November 27th 06 09:50 AM


All times are GMT +1. The time now is 04:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"