Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 3,921 times

Contents

    Working With Control Arrays of Checkboxes in VB6 - Designing the Form

    sync_or_swim

    Designing the Form

    Special Thanks for the Code goes to Erwin B.

    This code is useful if you need to offer the user a range of choices in the form of checkboxes.  To save the user checking every single box there is a box marked "All" which, when checked, will turn off all of the other selections and vice versa, when any other box is checked the "all" box will be turned off if it is on.

    Although this sounds simple enough, it can prove to be frustrating because when you set the checkboxes value property in their click event it has the effect of creating a recursive loop because the click event calls the procedure which changes the checkboxes value, which in turn triggers the on click event etc.  The result of this is the error "Out of Stack Space".

    The way to deal with this is to create a control array of checkboxes (if you are unsure how to create a control array check out James's tutorial http://www.developerfusion.co.uk/show/188/) to deal with the various selections and a single checkbox which will signify all selections.

    To create the simple form for use in this demonstration first add a Frame to the form and give it a meaningful name and type something meaningful in its Caption Property.  To this frame add a Checkbox Control, just select the checkbox icon in the toolbox and drag it out onto the Frame (important to put it onto the frame as opposed to the form itself).  Change the name of the checkbox to chkOptions, right click on the control itself, select copy, then
    paste it anywhere within the Frame.  The option to create a control array will be displayed, click Yes to accept this, you may then paste as many checkboxes as you require.  When you paste a checkbox it will appear in the top left corner of the frame, just drag it into place and change its Caption property accordingly.

    Once you have added a checkbox for each of the options it is necessary to add the checkbox which will check/uncheck all of the other boxes.  It is important that this checkbox is created by selecting the checkbox control from the tool box and dragging it out onto the frame as before, not by pasting another copy.  Once you have created this checkbox you can change the name to something meaningful (chkAll), and set its Value property to "1 - Checked".

    The form should now look something like this:

    Comments