OK: because both answers ask for more data, I tried some more tests and found working cases:
Case “1”
Case “August”
Compiles.
The following produce the error message
Case FirstName = “Emile”
Case Right(FirstName,1) = “e”
OK (BIS): I now understand the error. In both cases above, the result of the evaluation is a Boolean !
Thanks, I got it. It was 5:30 (on a 24 Hours Clock) when I wrote that. I replaced the Select Case Block by an If ElseIf Block with many empty lines and it is as clear as a Select Case and works fine !
I wasted one hour on this simple error.
BTW: is the IDE report cautionable ?
(it shows the error in the Select Case line instead of in the Case line(s))
PS: I checked on a C++ for Dummies book switch(expression) and found nothing except a ‘bug’ in the 2002 edition: they used in the example ‘cas’ instead of ‘case’. Certainly a translation error.
Thank you for your answers. Roger says that Select Case works and Michel also ask for code; this leads me to think different and found where the error lies (my error).
Worst, it took me times to understand what I read: Select Case True My brain escaped True !!!
Nota: I choosed Select Case because its reading is far better than an If / End If block
But after adding extra spaces in the Select Case converted to If / End If code, it happens that the new code is as readable as the previous one.
Another question: do we know if there is a difference between these two ways of doing things ( Select Case vs If / End If ) in speed ?
[quote=144865:@JrmieLeroy]Regarding speed it depends actually.
Select Case is quicker when you evaluate a function but If/End If is quicker if you evaluate a property.
For example:
Function evaluateString(str As String)
//Takes 100ms to evaluate
Return str
End Function
If evaluateString("toto") = "123" then
//Do something
Elseif evaluateString("toto") = "456"
//Do something else
End If
Select Case evaluateString("toto")
Case "123"
//Do something
Case "345"
//Do something else
End Case
Select Case is quicker because it calls evaluateString only once.[/quote]
But you could store the value of evaluateString in a variable, which would mean that you only have to call it once.
‘select case’ vs ‘if … else’ has an innegligible difference in speed when running. Choosing between the two should depend on how easy the code is to read and write.
If evaluateString("toto") = "123" then
//Do something
Elseif evaluateString("toto") = "456" then
//Do something else
End If
If it is worth the optimization I would personally write the code like this:
dim evaluateStringToTo as string = evaluateString("toto")
If evaluateStringToTo= "123" then
//Do something
Elseif evaluateStringToTo = "456" then
//Do something else
End If
Adding empty lines before each and every ElseIf / Else add clarity / readability to the whole if block and that is what I was searching initially / why I choosed Select Case.