?
Solved

copy classes

Posted on 1998-12-03
9
Medium Priority
?
139 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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