Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

How to pass a Control to a Sub?

I have an ActiveX control that I can drag and drop onto a form. It has no way to create the object on the fly, rather it must be dragged and dropped onto the form. It is a third party object.  I need 10 instances of this control, so I have dragged 10 of them on to my form. They are called x1, x2, x3, etc.

I now have set the various properties to values such as:
x1.Color = vbRed
x1.Speed = 1
x2.Color = vbBlack
x2.Speed = 5

How do I pass these objects to a function to set the properties?  I want to do something like this:

Call SetProperties( x1, vbRed, 1 )
Call SetProperties( x2, vbBlack, 5)

I tried:
Public Sub SetProperties( MyObj as Object)   but it does not allow me to access the properties.

I tried:
Public Sub SetProperties( MyObj as Control)   but it does not allow me to access the properties either.

Thank you.

1 Solution
Simply set the "as" property in your Sub to the same name as the Control name you dragged onto your form. You should see it listed in the drop down box after you type the "as".  It will then allow you to access the properties.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now