Xojo 2023 r1.1 Select Case bug - is it fixed?

Hi folks:
This code produces the message “wrong” for me. Does this work correctly for you in what Xojo version?

Var st as string = "m"
Select Case st
 Case "M"
  msgbox ("wrong")
 Case "m"
  msgbox ("right")
End Select

or have I misunderstood the Case rules?

Xojo string comparisons are case insensitive by default. Isn’t a Select Case bug, the same will happen with this code:

Var st As String = "m"
If st = "M" Then
  MessageBox("wrong")
ElseIf st = "m" Then
  MessageBox("right")
End If

For case sensitive string comparisons, you can use String.Compare. This will work with your case sensitive example:

Var st as string = "m"
Select Case 0
Case st.Compare("M", ComparisonOptions.CaseSensitive)
  msgbox ("wrong")
Case st.Compare("m", ComparisonOptions.CaseSensitive)
  msgbox ("right")
End Select
1 Like

Read through this recent thread on case sensitivity in Xojo

You are wrong; this is SELECT CASE.

Not related to the character case. (Mm)…

Thanks, Ricardo. In my code, it looks like ComparisonOptions.CaseSensitive is needed almost everywhere where alphanumeric comparisons are made. But, for this one-letter Select Case, this is an easier workaround for me, especially as most of the work can be done with a simple regex applied to the existing code:

var st as string = "m"
select case asc(st)
case asc("M")
  msgbox ("wrong")
case asc("m")
  msgbox ("right")
end select
1 Like

Just remember that RegEx defaults to case insensitive too.

This reply isn’t useful.

4 Likes

Thanks, Kem. I don’t trust Xojo’s regex, so I do regex on the saved .xojo_code files. For instance, NotePad++ has a “Match Case” option.

So does Xojo.

Thanks, Tim. Did not notice the RegExOptions. This makes me wonder: since there is a Match Case option for RegEx, why isn’t there one for regular code?

You mean ComparisonOptions.CaseSensitive?

2 Likes

This is a kind of a mess in the language, it causes even unknown bugs. I think that Xojo needs a set of strict operators (case sensitive), as an inspiration maybe could be the opposed of those used by some IBM products (e.g. ObjectServer SQL), where = > < etc are case sensitive and the prefix “%” make them insensitive.

For Xojo it would be the other way around as:

"a" = "A" // True
"a" = "a" // True

"a" %= "A" // False, case sensitive equal
"a" %= "a" // True

"a" > "A" // False
"a" > "a" // False

"a" %> "A" // True, case sensitive "greater than"
"a" %> "a" // False

So a code like this would work:

Var st As String = "m"
Select Case st
 Case %"M" // same as {Case Is %= "M"} // Consider binary string
  msgbox ("wrong")
 Case %"m" // same as {Case Is %= "m"} // Consider binary string
  msgbox ("right")
 Case Is %< "a"
  // whatever
 Case Is %< "A"
  // Whatever
End Select

Isn’t remarkable that a statement so simple and obvious would be such a problem?

It might be nice if this example of .compare is in the documentation.

I use Asc

Thanks,

Simple is, obvious no, or one guy (and many others) would not classify the behavior that he found (because most languages do not behave this way) as a bug.

What you do with ASC() is called workaround. As I said, it would be better if the language had proper (direct and faster) support for case sensitive content right in the language (like operators and literals).

1 Like

I think Emile was pointing out that “case” in this context does not refer to upper or lower case.

But the Select keyword here is not optional.

1 Like

My bad. I read it wrong. Sorry.

1 Like

you could do (because m<>M)

Var st As String = "m"
Select Case st
Case "M","m"
  MsgBox ("M or m")
Case Else
  MsgBox ("Else")
End Select


Select Case st.Lowercase
Case "m"
  MsgBox ("m")
Case Else
  MsgBox ("Else")
End Select

I’m sorry Markus, I don’t understand.

How that will help to know if the original letter was ‘m’ or ‘M’?

Any way his answer makes no sense and is not helpful.

String comparisons, in most cases, are case insensitive. as some has already answered, easiest and fastest way is to do it with Asc as Carl sugested:

Var st As String = "m"

Select Case st.Asc
Case 77 'M
  msgbox("wrong")
Case 109 'm
  msgbox("right")
End Select
1 Like

How that will help to know if the original letter was ‘m’ or ‘M’?

i guess Mike expect true for m or M, Human like compare.
its not about separate m and M.