
Create ActiveX instance at runtime
Quote:
> Did not work i tried ...
> Public MyImage(100) As Image
> '-- Image1 is an image on the Formwindow
> 'Set MyImage(MyImageCount) = Image1
> 'Set MyImage(MyImageCount) = New Image1
> Set MyImage(MyImageCount).Picture = LoadPicture(MyTrim(stri))
What you have to do in the above example is:
Public MyImage(100) As Image
Load MyImage(ImageCount)
MyImage(ImageCount).Picture = LoadPicture(picfile)
You have to use Load, because you are declaring it as an array.
Don't use the Set command to assign properties. It is only
used to assign an object variable to an object.
Also remember that if you create two object variables, and
set one equal to the other, they will both point to the same
object.
If you do like this:
Public MyImage as New Image
Public MyImag2 as Image
Set MyImag2 = MyImage
Then MyImag2 points to the same object as MyImage
To have two independent instances of the same
type of object, you have to use the New keyword
on both.
Public MyImage as New Image
Public MyImag2 as New Image
Then, to copy the properties of one to another, you
have to do it one at a time. You can't use
Set MyImag2 = MyImage
because it redirects MyImag2's pointer to MyImage
and you no longer have two independent objects.
And you can't do this:
MyImag2 = MyImage
because VB won't let you.
What you have to do is:
MyImag2.Picture = MyImage.Picture
MyImag2.Border = MyImage.Border
. . .etc.
until all the properties you want
to copy are copied.
jdm