Solved

copy classes

Posted on 1998-12-03
9
133 Views
Last Modified: 2010-05-03
Hi,
I want to ask how can I copy a content of one class to another (of the the same type), with no setting a reference.
what I mean is this:

dim a as new myClass
dim b as new myClass
b = a  (NOT set b = a)
0
Comment
Question by:s_lavie
9 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1447977
The best solution is adding a function to your class to copy the members : CopyOwnClass(clsDest as myClass)

So, you could do as follow :

   Sub CopyOwnClass(clsDest as myClass)

       With clsDest
           .A = A
           .B = B
       End With

   End Sub

0
 
LVL 2

Author Comment

by:s_lavie
ID: 1447978
Sorry waty, but this is the naive way to do so, it's not what I meant. What if you have a lots of vars in a class - would you do the same??? It's not realistic.
In C++ you just do a = b or *a = *b. Is there a similar way in VB?
0
 
LVL 14

Expert Comment

by:waty
ID: 1447979
Error, in C++ if you do a=b; you copy the adress. So if your class contains pointer, you could go to have some incoherences.

Under C++, you have to construct a copy constructor. In this copy constructor, you copy all the members as you need. It is the same under VB, but you have to call explicitely to the copy function.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 1447980
It seems to me that there must be another way, otherwise I wouldn't ask that question.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:waty
ID: 1447981
If you know another way, I would like to know it too.

Drop a mail to Microsoft.
0
 
LVL 3

Expert Comment

by:hakyemez
ID: 1447982
dim a as new myClass
dim b as myClass
set b = a

0
 
LVL 2

Author Comment

by:s_lavie
ID: 1447983
Hi hakyemez,
your answer setes a reference to of the class, but I want a completly different class with the same values, with out any connection, (like in numeric vars).
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 total points
ID: 1447984
Impossible without coding.

Very simple reason:
A has a reference to an object C
Should B now get the reference to same object C or should C be copied.

You have to do it the way Waty says.

0
 
LVL 2

Author Comment

by:s_lavie
ID: 1447985
Sorry Waty,I probably misunderstood the way it works!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now