Consulting

Results 1 to 3 of 3

Thread: Solved: Problem with an awfull lot off checkboxes

  1. #1
    VBAX Newbie
    Joined
    Apr 2005
    Posts
    4
    Location

    Solved: Problem with an awfull lot off checkboxes

    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

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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
    [VBA]Dim ctrl As Control
    For Each ctrl In UserForm1.Controls
    If Left(ctrl.Name, 3) = "chk" Then ctrl.Value = False
    Next[/VBA]
    K :-)

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,710
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •