I have a game, and i have two option boxes in a frame. I need to do a check to see that one of them has been checked.
How would i go about this?
Printable View
I have a game, and i have two option boxes in a frame. I need to do a check to see that one of them has been checked.
How would i go about this?
:)VB Code:
If Option1.Value = -1 Then 'Selected ElseIf Option2.Value = -1 Then 'Selected Else 'No selection made End If
These are my two option boxes in the frame
If Option1.Value = vbchecked Then
Green = Green + 1
End If
If Option10.Value = vbChecked Then
Yellow = Yellow + 1
End If
I cant see how that could would go in there????
Sorry
In my code a True is the same as a -1. I forgot the negative sign. Updated my post already.
If Option1.Value = vbchecked Then
Green = Green + 1
End If
If Option10.Value = vbChecked Then
Yellow = Yellow + 1
End If
they are the option boxes in one frame. the words yellow and green are variables. Where would your code go?
L
I guess your loosing me as your code is basically the same thing. Does it not work for you?
What event do you need to check for th option values? A button click, checking of the option button? etc.
ah i see where im confusing you! haha
I have 18 frames all with 2 option buttons (36 option buttons).
before the user can exit this form via a button. I need to make sure that 18 boxes have been selected.
1 option button per frame
how do i do this?
Easy way is to just do an If Then ElseIf block on each pair and keep track with a boolean variable. Set it to True if there is a pair that is missing a selection.
VB Code:
Private Sub cmdClose_Click() Dim bMissingSelection As Boolean bMissingSelection = False If Option1.Value = vbChecked Or Option2.Value = vbChecked Then 'One selection is present Else bMissingSelection = True End If If Option3.Value = vbChecked Or Option4.Value = vbChecked Then 'One selection is present Else bMissingSelection = True End If '... If bMissingSelection = True Then MsgBox "Not all selections have been made!", vbOkOnly+vbExclamation End If End Sub
But
if option1 is checked then i need green = green + 1
how can i code that in
Just add the line of code to the option(s) where it should be increased.
VB Code:
Private Sub cmdClose_Click() Dim bMissingSelection As Boolean bMissingSelection = False If Option1.Value = vbChecked Then 'One selection is present green = green + 1 ElseIf Option2.Value = vbChecked Then 'One selection is present green = green + 1 Else bMissingSelection = True End If If Option3.Value = vbChecked Or Option4.Value = vbChecked Then 'One selection is present Else bMissingSelection = True End If '... If bMissingSelection = True Then MsgBox "Not all selections have been made!", vbOkOnly+vbExclamation End If End Sub
Don't use VBChecked, it's for Checkboxes not OptionButtons. vbChecked = 1, what you need is -1 (-1 = True) like Rob did in post #2, so it should be..
VB Code:
If Option1.Value = True Then 'Or If Option1.Value Then
Good catch jcis! :) I started out good and its been a while since I really used VB 6 so I assumed it was correct for the option button to have vbChecked when that is just for the checkbox control. :(
VB Code:
Dim Option1_Index as Integer Sub Option1_Click(Index as Integer) Option1_Index=Index End Sub
You can easily keep track this way for each option pair.
BTW: You should default one selection in each pair.
Private Sub cmdClose_Click()
Dim bMissingSelection As Boolean
bMissingSelection = False
If Option1.Value = vbChecked Then
'One selection is present
green = green + 1
ElseIf Option2.Value = vbChecked Then
'One selection is present
green = green + 1
Else
bMissingSelection = True
End If
If Option3.Value = vbChecked Or Option4.Value = vbChecked Then
'One selection is present
Else
bMissingSelection = True
End If
'...
If bMissingSelection = True Then
MsgBox "Not all selections have been made!", vbOkOnly+vbExclamation
End If
End Sub
but i need option1 to add to green and option10 to add to yellow.
but only one can be selected
how do i do this?
If eash of the two pairs can or are needed to be selected at the same time then you should switch over to checkboxes as option buttons only allow one of the group to be selected at a single time.
what?
can i have help with the coding?
im really lost now
Do you need option1 and option10 to both be selected at the same time? If so then they dont work that way. This is why I suggested switching over to use heckbox controls instead. ;)
no
i need either option1 or option10 selected.
If option1 is selected then i need green = green +1
If option10 is selected then i need yellow = yellow + 1
VB Code:
Private Sub cmdClose_Click() Dim bMissingSelection As Boolean bMissingSelection = False If Option1.Value = -1 Then 'One selection is present green = green + 1 ElseIf Option10.Value = -1 Then 'One selection is present yellow = yellow + 1 Else bMissingSelection = True End If '... If bMissingSelection = True Then MsgBox "Not all selections have been made!", vbOkOnly+vbExclamation End If End Sub
how do you clear everything you do, because when i tested it out it says the msgbox and when you click ok. it saves the points and goes back to the screen. How do i get around this?
In what event do you have the code? What do you mean clear everything ?
ok
I have this code in the submit button
When the user clicks on the OK button of the msgbox "Not all selections have been made!" it goes back to the menu screen and also it adds on to the variables.
I want it to clear the screen so the user can just start again.also i want to take the points off of the variables. I hope this makes sense.
Then you will have to write a procedure to loop through all your controls needing resetting and resetting then to whatever status you desire.
i dont know how to do that
Then after the MsgBox from your other procedure you can just call the sub.VB Code:
Private Sub ResetMe() 'Go through your controls needing resetting Option1.Value = 0 Option10.Value = 0 '... etc End Sub
Its not working
this is a snip of the code
If Option27.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option36.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
bMissingSelectionSelection = True
End If
If bMissingSelection = True Then
MsgBox "Not all selections have been made!", vbOKOnly + vbExclamation
Call Reset
End If
If bMissingSelection = False Then
frmMainMenu.cmdcribbage.Visible = False
frmMainMenu.Show
Me.Hide
End If
End Sub
Reset is that option1 = 0
i put it in the module and then it calls it
Its not finding any thing wrong with it, its not finding the errors!
Whats wrong with it?
It would be more helpful to post your project...
Am Option button will generate a -1 for True and a 0 for False. Step through your code and see where the code execution goes. I see this is for Option27 and Option36 now?
well they are all the same, cause there are 18 pairs on option boxes. look want me to upload it for you too see?
Yes, please. They are all the same in what respect?
here it is
has to be rar as its to big to be zipped
I dont have winrar so I can not view it. Why is it so large?
you got msn?
if so add me
[email protected]
and then i can send it to you over there
A few things...
Why are your frx files so large?
What form are you having trouble with? (frmscribbage)
What exactly do you want it to do?
You should start each module, form and class with Option Explicit.
It won't start for things are missing.
One thing, for each pair that you only want one selected. Place the pair on a picturebox or frame. Picturebox if you may use the manifest file later. In that way only one will allowed to be selected.
Better names for each option pair would be helpful also. Currently you have an option array that encompasses all options.
No MSN but sounds like Randem has access to the code. Sounds like you option buttons are not actually grouped as child objects of your frames (if you have frames). If not then cut and paste the option buttons into repesctive frames to isolate the exclusivity of each pair.
its not working still
i really dont know what to do
As per my last post, add some frames to your form. Cut and paste two pairs of option buttons inside each frame. That should take care of it.
please state more then "it doesnt work" as its really hard to etermine how and whats going on with such a generic statement. ;)
Actually, answers to my question would go a long way to help you.
BTW: delete those frx files you do not need them.
here is the work
I was wondering if you could help me with them now?
Lx