|
-
October 13th, 1999, 06:18 AM
#1
Passing Classes as arguments to other Classes
I am not able to pass classes to other classes.
In Class1, put the code
public A as Byte
In Form1, put the code
private Sub Form_Load()
Dim X as new Class1
Dim Coll as new Collection
X.A=25
Coll.Add X
'BookMark1
X.A=6
Coll.Add X
End Sub
When I make "X.A=6", the value of the first item in the collection also becomes "6". So, at BookMark1, I added the statement "Set X=Nothing". Is that necessary, or have I made a mistake somewhere? I have the same problem whenever I pass Objects to another Object.
Deepak
-
October 13th, 1999, 06:24 AM
#2
Re: Passing Classes as arguments to other Classes
you have been using the same reference. Of course, the value changed in X.
code like this:
dim x as class1
set x = new class1
x.a = 25
col1.add x
set x = new class1
x.a = 6
col1.add x
-
October 13th, 1999, 07:04 AM
#3
Re: Passing Classes as arguments to other Classes
Suppose I have a sub like
private Sub A( byval B as Class1)
'Code Here
'More Code
End Sub
Do I have to "Set B=Nothing" before I end the Sub? Or will this be done automatically?
Deepak
-
October 13th, 1999, 07:51 AM
#4
Re: Passing Classes as arguments to other Classes
IMHO you should not do it
-
October 13th, 1999, 12:08 PM
#5
Re: Passing Classes as arguments to other Classes
-
October 14th, 1999, 01:21 AM
#6
Re: Passing Classes as arguments to other Classes
common acronym in Email:
In my humble opinion
-
October 14th, 1999, 07:21 AM
#7
Re: Passing Classes as arguments to other Classes
I hope you understand difference between passing arguments ByVal and ByRef.
(If you pass variable ByVal, your sub cannot change original value of variable.)
For OBJECT variables, behaviour is different.
If you pass OBJECT variable ByVal, you CAN modify original Object properties, but you cannot modify its address (i.e. you cannot Set it to another object or destroy it).
See: http://www.**************/Item.asp?Pa...takeBank&ID=11
Since you are passing your object ByVal: Sub A(byval B as Class1) I thought you should have this info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|