Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class question

Status
Not open for further replies.

fugigoose

Programmer
Jun 20, 2001
241
US
I've made several classes, but i keep having the same problem. I can't seem to set one instance equal to another instance, though they are the same class, that is:

'---
private duck1 as new duck
private duck2 as new duck

duck1 = duck2
'----

This return the error "with or object block variable not set" or whatever. I can set individual properties, just not the whole instance. Is there a way to do this? Is there a function that needs to be in the class to tell it how to do this?

Any help will be appreciated!
 
Do you actually want to copy the class?
Or just another refrence to the class (which is what Set will do for you)?

Greetings,
Rick
 
I'd like to copy it, I think. I need it to be independent of the original class. I don't want duck2's changes to be applied to duck1. Is that what you mean? Thanks for the other help you guys. OMG I should've known SET, thats the problem I had with setting a pictureBox's image to a file. I just always assumed set was optional. So does that mean i have to write a public property set for everything in that class?
 
No, Set in this context is used in a statement to assign an object reference to a variable. You create separate instances of Duck by using New in each variable assignment.

Dim duck1 As Duck
Dim duck2 As Duck

Set duck1 = New Duck
Set duck2 = New Duck

Paul Bent
Northwind IT Systems
 
I know that paul, but i'm trying to set duck1 = to duck2. I can create them just fine.
 
You can create two new objects. (Duck1 and Duck2)
You can reference an existing object by another variable
(Set Duck2 = Duck1)

But when you do this then the original object contained in Duck2 is destroyed and Duck2 simply starts pointing to Duck1. i.e. for example, if you make a change in the properties of Duck1, that change will be reflected in Duck2 as well and vice-versa. There is no more distinct Duck2, i.e. you will not have an independent copy.

What you need is a copy (or clone) of the original object, Duck1. This is not possible in a VB class although it is possible in some true OOP languages like Java and VB .NET.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top