PDA

View Full Version : Solved: Select Case statement not working



jamescol
06-04-2004, 03:53 PM
OK - I've just hit a wall wiht something that should be simple :(

From an InputBox statement, I need to determine whether the user:

1. Clicked OK but did not enter anything
2. Clicked OK but did not enter a sufficient number of characters
3. Clicked Cancel

Here is how I have been trying to write the code:


strInput = InputBox("Enter something greater than 6 characters.")
Select Case strInput

'Check for a blank entry
Case (Len(strInput) = 0)
MsgBox "You must enter something."

'Check that the user entered the minimum length
Case (Len(strInput) < 6)

MsgBox "Your entry must be contain at least 6 characters"

'Check if the user pressed Cancel
Case ""
Exit Function

'If we get here, the string passes
Case other
Msgbox "Good job, you can follow directions!"

End Select


I'm sure the problem is simple. Ideas on what I'm doing wrong?

Thanks,
James

TonyJollans
06-04-2004, 04:17 PM
Hi James,

The statement ..

Select Case strInput

.. says "compare strInput to each of the following Cases".

Next you have case #1 ..

Case (Len(strInput) = 0)

.. so it compares strInput to (Len(strInput) = 0)

and, whether it is True or False, it is NEVER equal to strInput, so the condition is never fulfilled and it moves on to check the next condition.

You must either use some other construct, or use ..

Select Case True

.. followed by a series of complete conditions.

jamescol
06-06-2004, 12:06 AM
I get it! Guess we can mark this one Solved.