Solved

Something like a Pointer

Posted on 2001-06-19
4
158 Views
Last Modified: 2010-05-02
Hello,

I need something like a pointer to tell a class module where to get its data from. Is there such a possibility in Visual Basic?

Gretting
zz

0
Comment
Question by:zzconsumer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6205550
ByRef

in your class module you make a function like

public function myFunction(ByRef myData as string)
   msgbox myData
   myData = "Newstring"
end function

now you just pass the reference like

Dim str as string
str = "test"
call objectreference.myFunction(str)
msgbox str

Regards,
CJ
0
 
LVL 28

Accepted Solution

by:
Ark earned 100 total points
ID: 6205639
Hi

At ClassModule_Initialize event:

  MyClassPointer = ObjPtr(Me)

At bas module:

Public MyClassPointer As Long

Public Function ResolvePointer(ByVal lpObj&) As MyClass
  Dim oMC As MyClass
  CopyMemory oMC, lpObj, 4&
  Set ResolvePointer = oMC
  CopyMemory oMC, 0&, 4&
End Function

Now any time you want access any of your class properties or methods, just call:

Call ResolvePointer(MyClassPointer).MyMethod(params)
Or ResolvePointer(MyClassPointer).MyProperty = NewProperty

Cheers
0
 
LVL 1

Author Comment

by:zzconsumer
ID: 6205682
Can i also tell the class which Property of a known class to allocate? The thing is that I made a class that returns arrays using different Properties as Variant.
0
 
LVL 1

Author Comment

by:zzconsumer
ID: 6230438
Well, I had not time to check it out, but Ark's solution looks like it comes closest to what I need.

Thanks.
zz
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question