Solved

copy classes

Posted on 1998-12-03
9
135 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

776 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