Solved

Run-time creation of controls

Posted on 1998-08-21
1
130 Views
Last Modified: 2010-04-30
 Is it possible to create a control at run-time?
  Say I need to use ListBox control inside *class module* just for maintaining of the sorted list of items.

  If you are familiar with Delphi there this is really simple. You write just this
  someControl := TsomeControl.Create(nil);
where nil is the empty "owner" of someControl (which is normally Form).
After that you set all properties you need and that's it.

  If the answer is positive I will increase points for any
code example.
0
Comment
Question by:dksqrt
1 Comment
 
LVL 1

Accepted Solution

by:
jsuper earned 100 total points
ID: 1430295
Unforunatly, some controls cannot be created at run time, the listbox being one of them.  There is a rather simple workaround though.  Create a form and set it's visible property to false so that it will never display.  Place any controls you need at run time on this form.  For example, I usually name the form frmObjects.  Then, in your class, you redefine your objects as being the objects on the hidden form.  For example...

Options Explicit

Dim VList as ListBox

Private Sub Class_Initialize()
   Set vList = frmObjects.Listbox1
   ...
End Sub

Now these controls can be handled as if you had just created them in the class.   Hope that helps.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

758 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

17 Experts available now in Live!

Get 1:1 Help Now