Link to home
Start Free TrialLog in
Avatar of chaplt01
chaplt01

asked on

Very Easy Newbie VB QN

How do you create a control at runtime?  Say I want to create an array of combo boxes at runtime,  

Set DataComboMatrix(i, j) = ???
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GrahamSkan
You can only create an array at design time. You can do this by setting the index of a control to a number. So that you then might have a control such as Combo1(0).
You can add other members at run time with the load statement:

Load Combo1(1)
Load Combo1(2)

You can't create an array with more than one dimension, as in your example, though.
Avatar of FunkyMeister
FunkyMeister

You can create any client object at run time easily using API calls.

Though this can be risky if you're not familiar with API calls, a good suggestion is to search for "API" and "DrawFrameControl"

Declare Function DrawFrameControl Lib "user32" Alias "DrawFrameControl" (ByVal hDC As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long

A good place to look is AllAPI.net, they have a program (http://www.allapi.net/agnet/apiguide.shtml) there that'll let you scan and read up on these functions.  With the hDC of your window, you can ADD many types of controls to your window at runtime.  Just remember though, a good programming technique is to remove them before you're done (although a window will remove all clients inside of it at closure, it's always best to do your own housekeeping).

API calls aren't for the faint of heart, but having a program that keeps all the definations and what they mean (with examples), gives you a lot to go on.