VBNotebook Home | Articles | Dynamic Application Building in VB6
(These ideas are a consolidation of my newsgroup postings on this topic.)
I've used two basic designs for dynamic applications: a tabbed dialog interface and an Outlook interface. In each case, the definitions for the dynamic portion of the program were stored in a database and read in when the user selected the "applet" they wanted to run. In addition to the information for the controls, VBScript code was loaded into a scripting control on this form to provide additional functionality.
For the tabbed dialog version I used a tabstrip along with a "function bar" of buttons. Frames for the tabs and controls were added as needed for the definition. The action of the buttons on the bar was controlled by the VBScript code. The selection of the applet was controlled either through a front end selection dialog or by command line parameters.
For the Outlook style version, I started out with the Explorer application template and replaced the Listview control on the right with a picture box to act as the dynamic area. I decided to keep the treeview on the left side to display the available applets although I could have used an outlook icon bar on the left side instead. Since I knew from the start I'd have at least 50 or so of them in a about 10-20 different categories I thought the treeview would be a better choice. (I ended up having over 100 applets.)
One of my key ingredients in dynamic application building is my "Swiss Army Knife" control. This user control has several "template" constituent controls of various types (check list box, combo box, text box) as well as a scripting control. I have a few generic events, such as the Click event, mirrored through the user control as well as an "EventSink" event that returns events for specific controls (the type of event is a parameter passed into the event). I also have a method that allows me to pass a definition to the control. This includes placement information, the style of control to display, and VBScript code for initialization and for events that need special processing. When I need to add functionality to the application, I can add a new control definition to the database and it becomes available without having to redistribute the application to users. In projects I've used this method on, I've had between 20 and 30 definitions in the database.
I use a control array to add these controls to my dynamic forms instead of the newer Add method. I have a hidden, "zero", instance of the control that I use as a template for a control array. I've found using the older control array method to be more reliable and controllable than the new Add method in this case. Also, the Add method does not allow you to make an array of WithEvents objects and you can't add a control array.
I use an imaginary grid to position the controls. I use the length property of the control to determine how many "columns" it will used. As for rows, in some cases I've used tabs and in others I've used scrolling regions. Typically, I try to limit the number of controls on the screen to about 15. Some control types, such as checklist boxes, will take up more than one "row".
With the Validate event, there are some limitations/problems with this working right with constituent controls. Therefore, I added a method to validate the control that I could call as needed from either the Validate event on the main form or during other actions.
While there is some speed hit from using heavy user controls and VBScript, application performance has not proven to be a significant factor in the programs I've written using these designs.
__________________________________________________________________________________________
Copyright 2000-2005, J. Frank Carr