Solved

copy classes

Posted on 1998-12-03
9
137 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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