Assignment by reference or value

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi NG

I have a question about assignment of variables by reference or value.

I have a module where a collection C is defined as public.

In my form i want to use that information. Because i use a callback e.g.
button_click() i can not parse C in to the function. Instead i do the
following in the button_click() callback

dim A as collection
A = modSomething.C

Is A then a copy of C or is it a reference?
For performance reasons i would like it to be a reference.

Regards
Mark
 
Mark,

As far as I can tell from your description, A is neither a copy nor a
reference. It is not a copy as it will hold different data than C, and it is
not a reference as it is a new object in it's own right. It will have a
similar structure as C, being a collection, but will occupy a separate chunk
of memory, and this may be what you mean by copy.

I accept that you cannot pass C to the Button_Click event, but as it is a
public variable it is accessible within the form code, as you show, which
means that if you are happy changing it there, you do not need A.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Thanks! I should then use the WIDTH keyword





Bob Phillips said:
Mark,

As far as I can tell from your description, A is neither a copy nor a
reference. It is not a copy as it will hold different data than C, and it is
not a reference as it is a new object in it's own right. It will have a
similar structure as C, being a collection, but will occupy a separate chunk
of memory, and this may be what you mean by copy.

I accept that you cannot pass C to the Button_Click event, but as it is a
public variable it is accessible within the form code, as you show, which
means that if you are happy changing it there, you do not need A.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Mark,

Sorry, but I do not understand that comment.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob, I not sure that's right. My understanding is that A is a
reference (pointer) to C. A isn't a new Collection object in its own
right because it hasn't been instantiated. Rather it will just hold
the address in memory of C. Hence A *will* hold the same data as C.
Jamie.
 
I guess I saw New where there wasn't one. But, I just, and it even seems to
be the case when you New A(?).

I admit to being confused by what I am seeing, so it back to the books
methinks ( Curland's)

Bob
 
Back
Top