Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

copy classes

Posted on 1998-12-03
9
Medium Priority
?
140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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