Can objects be passed around as in Java?

P

peter

Can I pass a reference to an object to another object and have it access
its data?
It seems very little to ask for, coming from Java, but I get runtime
errors.




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
B

Bob Phillips

What you ask seems simple enough if I understand correctly. but show us what
you have tried, and explain what you are trying to do.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

peter

Well, here it is, but it's going to take a learning curve to figure out
my problem.
But maybe not; like I said, I'm new to Excel/VBA, and maybe it just
looks weird to me.

The main line creates oMACdefn objects of class clsMACdefn5A.
Each oMACdefn contains oFUNCTdefn objects of class clsFUNCTdefn5A.
I want to access the main line's wsWorksheet object from a method (for
now), but I first have a problem coding the Property method. Then the
main line doesn't seem to pass me a good wsWorksheet, tho it looks okay
in the debugger.

Hope it's not too difficult to get thru this stuff,
and maybe even to figure it out!
Thanks,
Peter.


main line :
Dim oMACdefn As clsMACdefn5A
Dim oFUNCTdefn As clsFUNCTdefn5A
Public wsWorksheet As Worksheet

BTW, the main line contains both oMACdefn and oFUNCTdefn's because it's
reading a page that contains the data for both.

clsMACdefn5A:
Private aAllFUNCTRows(1 To maxNumberFUNCTs) As clsFUNCTdefn5A

PROBLEM ONE -- How to code the Property that sets the oMACdefn object
into clsFUNCTdefn5A.

===========

Main line :
Set oFUNCTdefn = New clsFUNCTdefn5A
oFUNCTdefn.doParent oMACdefn 'Compile error,
'Invalid use of Property
' (see below)
oFUNCTdefn.setParent oMACdefn ' ok
' debugger shows obj

clsFUNCTdefn5A
Private oParent As clsMACdefn5A

Public Property Let doParent(ByRef inn As clsMACdefn5A)
Set oParent = inn
End Property
--OR--
Public Property Set doParent(ByRef inn As clsMACdefn5A)
Set oParent = inn
End Property


WORK AROUND:
============

clsMACdefn5A:
oFUNCTdefn.setParent oMACdefn

clsFUNCTdefn5A
Private oParent As clsMACdefn5A
Public Sub setParent(ByRef inn As clsMACdefn5A)
Set oParent = inn
End Sub


PROBLEM TWO -- why doesn't clsMACdefn5A.getWorksheet() work when called
from clsFUNCTdefn5A?

===========

clsMACdefn5A:
Public wsWorksheet As Worksheet
Set wsWorksheet = ActiveSheet ' Class_Initialize
Public Function getWorksheet() As Worksheet
Set getWorksheet = wsWorksheet
End Function

clsFUNCTdefn5A:
Private wsWorksheet As Worksheet
wsWorksheet = oParent.getWorksheet ' runtime error
' obj doesn't support funct/prop.
' this happens when it's getting back to
clsFUNCTdefn5A



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top