<<<Cneck Box>>> 
Author Message
 <<<Cneck Box>>>

I have several Check boxes in an array, grouped in three's.  What I want
to do is if you check say Check1(0) then Check(1) and Check(2) will
automatically be unchecked if already checked. This is what I have tried
in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
when you click on one of the three....

Private Sub Check1_Click(Index As Integer)

Select Case Index
    Case Is = 0
  Check1(0).Value = 1
  Check1(1).Value = 0
  Check1(2).Value = 0

    Case Is = 1
  Check1(1).Value = 1
  Check1(0).Value = 0
  Check1(2).Value = 0

    Case Is = 2
  Check1(2).Value = 1
  Check1(0).Value = 0
  Check1(1).Value = 0

End Select
End Sub

Is there any way else to do what I want to do with this????
Thanks in advance....
Kenny



Sun, 03 Jun 2001 03:00:00 GMT  
 <<<Cneck Box>>>
I have several Check boxes in an array, grouped in three's.  What I want
to do is if you check say Check1(0) then Check(1) and Check(2) will
automatically be unchecked if already checked. This is what I have tried
in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
when you click on one of the three....

Private Sub Check1_Click(Index As Integer)

Select Case Index
    Case Is = 0
  Check1(0).Value = 1
  Check1(1).Value = 0
  Check1(2).Value = 0

    Case Is = 1
  Check1(1).Value = 1
  Check1(0).Value = 0
  Check1(2).Value = 0

    Case Is = 2
  Check1(2).Value = 1
  Check1(0).Value = 0
  Check1(1).Value = 0

End Select
End Sub

Is there any way else to do what I want to do with this????
Thanks in advance....
Kenny



Sun, 03 Jun 2001 03:00:00 GMT  
 <<<Cneck Box>>>
You could use Option Boxes instead of Check Boxes.  If not, you could
change your code to the following:

Private Sub Check1_Click(Index As Integer)

        Dim iCount as Integer

        For iCount=0 to Check1.Count - 1
                if iCount <> Index Then Check1(iCount).Value=0
        Next

End Sub

--
Later,
Jody


http://www.visual-statement.com/vb



Quote:
> I have several Check boxes in an array, grouped in three's.  What I want
> to do is if you check say Check1(0) then Check(1) and Check(2) will
> automatically be unchecked if already checked. This is what I have tried
> in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
> when you click on one of the three....

> Private Sub Check1_Click(Index As Integer)

> Select Case Index
>     Case Is = 0
>   Check1(0).Value = 1
>   Check1(1).Value = 0
>   Check1(2).Value = 0

>     Case Is = 1
>   Check1(1).Value = 1
>   Check1(0).Value = 0
>   Check1(2).Value = 0

>     Case Is = 2
>   Check1(2).Value = 1
>   Check1(0).Value = 0
>   Check1(1).Value = 0

> End Select
> End Sub

> Is there any way else to do what I want to do with this????
> Thanks in advance....
> Kenny



Sun, 03 Jun 2001 03:00:00 GMT  
 <<<Cneck Box>>>
The trouble is that as you set the checked state of the checkboxes,
your routine gets called again....

So....  (Note changes to code)

Quote:

> I have several Check boxes in an array, grouped in three's.  What I want
> to do is if you check say Check1(0) then Check(1) and Check(2) will
> automatically be unchecked if already checked. This is what I have tried
> in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
> when you click on one of the three....

> Private Sub Check1_Click(Index As Integer)

  Static Busy as Boolean

  If Busy then Exit Sub
  Busy = True

Quote:
> Select Case Index
>     Case Is = 0
>   Check1(0).Value = 1
>   Check1(1).Value = 0
>   Check1(2).Value = 0

>     Case Is = 1
>   Check1(1).Value = 1
>   Check1(0).Value = 0
>   Check1(2).Value = 0

>     Case Is = 2
>   Check1(2).Value = 1
>   Check1(0).Value = 0
>   Check1(1).Value = 0

> End Select

  Busy = False

- Show quoted text -

Quote:
> End Sub

> Is there any way else to do what I want to do with this????
> Thanks in advance....
> Kenny



Sun, 03 Jun 2001 03:00:00 GMT  
 <<<Cneck Box>>>
What's happening is that setting a check box's value fires the Click event.
Thus, in the clickevent of a checkbox, setting it's value to some other
value (or, in the case below, in a control array and setting another control
element's value) causes a recursive call to the click event (which is why
you get a "Out of Stack Space" error).

To fix the problem, all you need is a static boolean (or int, if earlier
then v. 4) that keeps track of whether you are in a recursive call or not.
If you are, then don't do any code, just pop on out:

---In the Click event:

Static bAlreadyHere as boolean

if not bAlreadyHere then
    bAlreadyHere = true
    'Do your setting of the checkboxes now
    bAlreadyHere = false
end if

This way, whenever the code gets recursively called, your static value will
be set to true, so you wont go into the code that sets the checkbox's
values, staving off another round of recursion. Once you are done setting
the values of the checkboxes, you will set your variable back to false, so
that a normal "real" click will cause the proper action to take place.

--Tristan

Quote:

>I have several Check boxes in an array, grouped in three's.  What I want
>to do is if you check say Check1(0) then Check(1) and Check(2) will
>automatically be unchecked if already checked. This is what I have tried
>in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
>when you click on one of the three....

>Private Sub Check1_Click(Index As Integer)

>Select Case Index
>    Case Is = 0
>  Check1(0).Value = 1
>  Check1(1).Value = 0
>  Check1(2).Value = 0

>    Case Is = 1
>  Check1(1).Value = 1
>  Check1(0).Value = 0
>  Check1(2).Value = 0

>    Case Is = 2
>  Check1(2).Value = 1
>  Check1(0).Value = 0
>  Check1(1).Value = 0

>End Select
>End Sub

>Is there any way else to do what I want to do with this????
>Thanks in advance....
>Kenny



Mon, 04 Jun 2001 03:00:00 GMT  
 <<<Cneck Box>>>
Thanks to all that helped out here. I have tried all the examples and it
works GREAT now. Thanks again to all that helped out!
Merry Christmas and a Happy New Year to all!!
Kenny
Quote:

> I have several Check boxes in an array, grouped in three's.  What I want
> to do is if you check say Check1(0) then Check(1) and Check(2) will
> automatically be unchecked if already checked. This is what I have tried
> in the CLICK event the DOES NOT WORK. It gives an "Out of Stack Space"
> when you click on one of the three....

> Private Sub Check1_Click(Index As Integer)

> Select Case Index
>     Case Is = 0
>   Check1(0).Value = 1
>   Check1(1).Value = 0
>   Check1(2).Value = 0

>     Case Is = 1
>   Check1(1).Value = 1
>   Check1(0).Value = 0
>   Check1(2).Value = 0

>     Case Is = 2
>   Check1(2).Value = 1
>   Check1(0).Value = 0
>   Check1(1).Value = 0

> End Select
> End Sub

> Is there any way else to do what I want to do with this????
> Thanks in advance....
> Kenny



Tue, 05 Jun 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. <<<<<<<<ComboBox>>>>>>>>>>>>

2. HELP >>>>>>WIN API <<<<<<<<<<

3. help me out please!!!!<<<<<<<<<<<<<<<<<<<<<<<thanks>>>>>>>>>>>>>>>>>>>>>>>>

4. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

5. <<<<HELP- OLE container Control>>>>>>>>>

6. VB5<->RDO2<->ODBC<->ORACLE Procedure Problem

7. <<<Gif Files>>>

8. <<<CD ROM>>>

9. <<<Win32Api.TXT>>>

10. <<<NetWork Drv>>>

11. >>>> WAV file GRAPH <<<<<<<

12. >>>>HELP ME WITH DATEVALUE IN UK FORMAT<<<<<<<

 

 
Powered by phpBB® Forum Software