Solved

copying objects

Posted on 1999-01-15
4
123 Views
Last Modified: 2010-05-03
Please can soemeone help...i have a control on a form and i would like to be able to have an exact replica created when a button is clicked...the control in question is part of a control array....
basically i need to copy an object, clone it in other words..
thankyou very much
0
Comment
Question by:cybermoonlight
4 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1456586
You probably now how to add a new entry to the control array.
But here is some code

i = ubound(contarray)+1
load contarray(i)
contarray(i).move left,top, width, height
contarray(i).show

0
 
LVL 10

Accepted Solution

by:
caraf_g earned 120 total points
ID: 1456587
You will have to copy each property individually.

Use the load method to create a new element in the control array and then, for each property do:

NewControl.Property = OldControl.Property

This works for all properties that are standard datatypes. For any Object type properties you must copy THEIR properties individually:

NewControl.SomeObjectProperty.Property = OldControl.SomeObjectProperty.Property

Except if such a property is an object property......
and so on.. and so forth..

There is no "single statement" solution for this problem.


0
 
LVL 4

Expert Comment

by:chabaud
ID: 1456588
Your could use the "TypeLib Information" library (TLBINF32.DLL) to make a generic CopyObject function.
Just list all the source object properties, and for each, invokeHook-get from the source object and invokhook-put to the target object.

Use On Error Resume Next to skip read-only, and design-time only properties...


0
 
LVL 2

Author Comment

by:cybermoonlight
ID: 1456589
cheers caraf..shame vb doesn't have a built in function....thankx
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now