Results 1 to 12 of 12
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    select only checked boxes (vb6)

    Hi
    How can i loop through a group of checkboxes to see which are ticked?

    i need to specifically loop through the checkboxes on the active tab of a tab control. I need something like:
    for each chkBox in myform.mytabcontrol.activetab.chkboxes
    if mychkbox then
    do stuff
    end if
    next chkbox

    but this doesnt seem to be the way that VB needs it.
    can anyone give me any clues please ?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: select only checked boxes (vb6)

    Are the checkboxes in a control array? If so, you can loop though them by using something like this, assuming that Check1 is the name of the control array:

    Dim intCnt As Integer
    Dim intWhatever As Integer

    intWhatever = Check1.UBound

    For intCnt = 0 To intWhatever
    Debug.Print Check1(intCnt).Value
    If Check1(intCnt).Value = 1 Then
    Beep
    End If
    Next intCnt

    Checkboxes in VB have a value of 0 or 1.
    Charlotte

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    If you want the checkboxes on a tab called "Page2", it could be done like this:
    [pre]Private Sub UserForm_activate()
    Dim ctlControl As Control

    For Each ctlControl In Me.Controls
    If TypeName(ctlControl) = "CheckBox" Then
    If ctlControl.Parent.Name = "Page2" Then
    Debug.Print ctlControl.Value
    End If
    End If

    Next

    End Sub[[pre]
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    yes, the checkboxes are in a control array(per tab). however i dont want to go through every checkbox on the form (unless i have to!) as some checkboxes, on other tabs, may well be ticked too.

    do i have to loop through EVERY checkbox or can i , knowing the tab that is active, loop through just the checkboxes on that tab.

    given that i can tell the tab that i am on, can i then tell what the control array is called or do i have to hard code it ?

    i have been reading about using a frame or picturebox to hold the controls on each tab but this seems an awkward way of coding this. is this because there is no control collection for a tab ?

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    Geoff, when you refer to Tab2, is that the control name or the name of a tab on control ? I cannot find any way to give individual tabs names, VB only goves the chance to attribute a number to the 'Tab' value.

    is looping through every control on the form the only way to find the controls on a particular tab ? is there no tab.controls collection ?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: select only checked boxes (vb6)

    Are there separate control arrays on the tab pages or a single controls array? If you have separate arrays, you only need a Select Case statement to deal with the specific control array you want.

    Looping through the checkboxes is fast, so what's the problem with doing it? In VB you aren't using a native tab control the way you are in Access and the VB version doesn't have some of the niceties of the Access tab control.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    Fatherjack,

    I've used the VBA Multipagecontrol rather than the tabstrip control to get this result. Sorry, I didn't realise until I checked it again. There are other controls avaialable in VB6 though. Which control are you using? There are add-on tab controls as well as the default.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    yes, each tab page has a bespoke control array of checkboxes.

    i dont have a problem with going through every control, it just seems a waste !?

  9. #9
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    i am using the Microsoft TabbedDialog Control 6.0 (SP5), according to the components dialog in VB6. When you hover over it in the toolbar the tooltip says SSTag

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: select only checked boxes (vb6)

    That's also the one I set up to test. It works but it "ain't pretty", so to speak. There doesn't appear to be a way to name the tab pages, but you can use the value of the tab control to tell you which page is visible. Using that, you can determine which control array or which part of an overall control array of checkboxes to cycle through.

    Edited for correction-Charlotte

    I'm wrong. There is a caption property for the tab control, but you have to set it from code. Also, you don't use the *value*, you use the tab property of the control to determine which page is visible. Sorry about that. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Charlotte

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: select only checked boxes (vb6)

    thank you both, with the combined suggeestions in the thread i have got the control performing as i wanted, maybe not quite as neat a piece of code as i had hoped for but it works.

    thanks again

    charlotte,re: 'it aint pretty but it works' - is there a different control that you would suggest i use for another time ?

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: select only checked boxes (vb6)

    I generally avoid activeX controls, and I don't work in VB enough to have a suggestion. Maybe someone else will jump in with one though. Or you could try the tabstrip control that Geoff mentioned.
    Charlotte

Posting Permissions

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