How does that answer any of the questions????
This is getting most difficult... :(
Printable View
How does that answer any of the questions????
This is getting most difficult... :(
i have got another problem and i cant see where i am going wrong.
I got it all working BUT it thinks all the boxes need to be ticked not just half of them, cause when i test it, it says the error message that i put in.
how do i get it right?
CODE
Private Sub cmdsubmit_Click()
Dim Miss As Boolean
Miss = True
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
Miss = False
End If
If Option2.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option11.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option3.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option12.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option4.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option13.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option5.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option14.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option6.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option15.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option7.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option16.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option8.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option17.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option9.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option18.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option19.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option28.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option20.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option29.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option21.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option30.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option22.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option31.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option23.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option32.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option24.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option33.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option25.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option34.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
If Option26.Value = -1 Then
'One selection is present
Green = Green + 1
ElseIf Option35.Value = -1 Then
'One selection is present
Yellow = Yellow + 1
Else
Miss = False
End If
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
Miss = False
End If
If Miss = False Then
MsgBox "Not all selections have been made!", vbOKOnly + vbExclamation
End If
If Miss = True Then
frmMainMenu.cmdcribbage.Visible = False
frmMainMenu.Show
Me.Hide
End If
End Sub
Ok, I officially give up :eek: :confused:
That's how you've coded it at the moment. The error message will appear until you've selected an option in each frame.Quote:
Originally Posted by lauram340
As suggested earlier use a control array of option boxes, with two option boxes per frame and in proper order. eg. 1st frame has option(0) and option(1), 2nd frame has option(2) and option(3). And name the control array something appropriate... for sample I used optSelections
Now wrap the check (that selections are complete) in a function. Call the function whenever you need to check that the selections are complete.
After checking that selections are complete, proceed with rest of algorithm in cmdSubmit(). You can simplify If-Else since your dealing with pairsof option buttons and option buttons within the same container are exclusive (only one of them is True, others default to false)VB Code:
Public Function CheckSelections(ByRef RetMsg As String) As Boolean Dim lIndex As Long Dim lSelectedCnt As Long CheckSelections = True 'init return value to True For lIndex = optSelections.LBound To optSelections If optSelections(lIndex).Value Then lSelectedCnt = lSelectedCnt + 1 If (lIndex + 1) Mod 2 = 0 Then 'just finished iterating a pair If lSelectedCnt < (lIndex + 1) \ 2 Then '(lIndex +1) \ 2 returns pair count 'no selection for previous pair... 'if pair count =1 then selected count should =1 RetMsg = "Please select between option " & lIndex & " and " & lIndex + 1 'lIndex and lIndex +1 to adjust option button index (zero based) to count (one based) CheckSelections = False Exit For End If End If Next End Function
VB Code:
Private Sub cmdSubmit_Click() Dim strRetMsg As String Dim lIndex As Long If CheckSelections(strRetMsg) Then 'selections complete 'since selections complete, we simply iterate through the array and increment For lIndex = optSelections.LBound To optSelections.UBound Step 2 'Step 2 makes us iterate through even numbered option buttons If optSelections(lIndex).Value Then 'all even indexed option buttons for green Green = Green + 1 Else 'implied, odd numbered for yellow. 'If green not selected and since selections are ensured to be complete, then yellow was selected. Yellow = Yellow + 1 End If Next Else MsgBox strRetMsg End If End Sub
cheers guys!
If you have no more questions then please mark the thread as resolved. Thanks.
ok, will do.
will checkw what you guys have said and then i will :)