Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Something like a Pointer

Posted on 2001-06-19
4
Medium Priority
?
163 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
  • 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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