• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Something like a Pointer

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
zzconsumer
Asked:
zzconsumer
  • 2
1 Solution
 
CJ_SCommented:
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
 
ArkCommented:
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
 
zzconsumerAuthor Commented:
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
 
zzconsumerAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now