Newbie Simple Check Box Question

Symee
04-11-2003, 09:07 AM
Hi,
I am designing a form with four check boxes on it. I want to be able to only have one box checked at any one time. I have written the following code:

Private Sub Not_Rated_Click()
'On this page only one box is allowed to be checked at one time, so the code below _
clears all of the other boxes when not rated box is clicked:
Not_Rated = 1
OneStar_Rated = 0
TwoStar_Rated = 0
ThreeStar_Rated = 0
FourStar_Rated = 0
End Sub


Private Sub OneStar_Rated_Click()
'On this page only one box is allowed to be checked at one time, so the code below _
clears all of the other boxes when one star box is clicked:
Not_Rated = 0
OneStar_Rated = 1
TwoStar_Rated = 0
ThreeStar_Rated = 0
FourStar_Rated = 0
End Sub

Private Sub TwoStar_Rated_Click()
'On this page only one box is allowed to be checked at one time, so the code below _
clears all of the other boxes when two star box is clicked:
Not_Rated = 0
OneStar_Rated = 0
TwoStar_Rated = 1
ThreeStar_Rated = 0
FourStar_Rated = 0
End Sub

Private Sub ThreeStar_Rated_Click()
'On this page only one box is allowed to be checked at one time, so the code below _
clears all of the other boxes when three star box is clicked:
Not_Rated = 0
OneStar_Rated = 0
TwoStar_Rated = 0
ThreeStar_Rated = 1
FourStar_Rated.Value = 0
End Sub

Private Sub FourStar_Rated_Click()
'On this page only one box is allowed to be checked at one time, so the code below _
clears all of the other boxes when four star box is clicked:
Not_Rated = 0
OneStar_Rated = 0
TwoStar_Rated = 0
ThreeStar_Rated = 0
FourStar_Rated = 1
End Sub

When I run this code it comes up with run time error 28 "Out of Stack Space"

Can anyone help?

Thanks
Symee

dexmix
04-11-2003, 09:27 AM
thats cause you are running out of stack space :D
when you set Not_Rated = 1, this triggers its click event.
so basically your infinitely triggereing all your click events.
Why dont you use the radio control? it has this functionality built in, and when people see a radio control, they know what kind of behaviour to expect.

KenChen
04-13-2003, 09:57 AM
by using control array such as

Rate() control array

In the Rate_Click event

uncheck all

Rate(index).value = 1

is it the thing that you want ??

MindGenius
04-14-2003, 01:37 PM
One of the ways, if you really don't want to go to radio buttons, is make a loop or make a constantly running timer, with code going something like:

If Check1.Value = 1 Then
Check2.Value = 0
Check3.Value = 0
Check4.Value = 0
End If
If Check2.Value = 1 Then
Check1.Value = 0
Check3.Value = 0
Check4.Value = 0
End If
If Check3.Value = 1 Then
Check1.Value = 0
Check2.Value = 0
Check4.Value = 0
End If
If Check4.Value = 1 Then
Check1.Value = 0
Check2.Value = 0
Check3.Value = 0
Hope this helps! :cool:

theroffler
04-14-2003, 08:17 PM
Why don't use just use optionboxes?

chuckroc
07-14-2003, 09:23 AM
What I usually do to work around this issue is to do the following....

Declare a module level variable (ie: m_Processing as boolean)

Then on the click event, I would do something like this...

Private Sub Not_Rated_Click()
'On this page only one box is allowed to be checked at one time, so
the code below _
clears all of the other boxes when not rated box is clicked:
If m_Processing=True then Exit Sub

m_Processing=True
Not_Rated = 1
OneStar_Rated = 0
TwoStar_Rated = 0
ThreeStar_Rated = 0
FourStar_Rated = 0
m_Processing=False

End Sub

By doing it this way, none of the other Click events will be fired, while the other values are being set.

Another way around this is to use the Mouse Up event instead of the click event. The Mouse up Event doesnt fire when you set the value of the check box.

Hope this helps

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum