PDA

View Full Version : [SOLVED:] Problem with an awfull lot off checkboxes



jokko
04-03-2005, 01:40 PM
Dear reader,

I am writing a program to determine how to connect power cables to electric panels and a userform with a diagram and 36 checkboxes seems to build an excellent interface. I want to use the checkboxes in the diagram to let the program show me what to do.

The only thing I could come up with would look something like this:

checkbox1.value = false
checkbox2.value = false
'
'
'
etc

if condition1 =true then
checkbox1.value = true
end if

if condition2 =true then
checkbox2.value = true
end if
'
'
'
etc.

Now with 36 checkboxes this will be an awfull lot off code. I think there must be a shorter way of doing this and I think class modules are the key. I can?t figure out how though. Does anybody have a sugestion?

Thanks in advance. Jokko
:doh:

Killian
04-03-2005, 05:23 PM
Hi jokko,
there are maybe a few ways to do this but I find the easiest is to use standard naming convention for control names (a prefix depening on its type; text boxes txtxxxx, check boxes chkxxxx, labels lblxxxxxetc) and then that property can be used to test for control types. i.e. name all checkboxes "chkSomename", "chkSomeothername", etc, then use this


Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If Left(ctrl.Name, 3) = "chk" Then ctrl.Value = False
Next

Jacob Hilderbrand
04-03-2005, 05:41 PM
Another option is to use the Tag property. You can set whatever text you want for the Tag property and use it to group similar controls.

And of course there are Class Modules.