1. We will be in Read Only mode (no new threads, replies, registration) starting at 9:00 EDT for a number of hours as we migrate the forums to upgraded software.

VB6 question. Is there an easy way to copy member variables during object...

Discussion in 'Programmer's Corner' started by kender, Jun 24, 2008.

  1. kender

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    VB6 question. Is there an easy way to copy member variables during object assignment instead of making a reference?


    I wasn’t able to find a definitive answer to this one on the web. Is there a way in VB6 to make a copy of an object without writing a copy function? What’s the best way to go about it?

    - Nick

    P.S. I’m writing my first VB6 classes. In C++ the default assignment operator copies the member variables to the new object. May be that’s what’s confusing me.
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    To start off, I don't know the answer to your question, and I wasn't able to find out much about copy constructors and the like in the VB6 documentation on MSDN. Also, my expertise is more with C, C++, and C#, not VB.

    Having said that, maybe you could find out by creating a couple of instances of one of your classes, and then assigning one to the other. If your class is relatively simple (with no members that are objects), it seems to me that the assignment operation should work. OTOH, if you have a more complicated class, you will probably need to come up with a copy operation so you don't wind up with multiple references to the same memory.