Android Question Combobox and Select Case confusion

Setlodi

Member
Hi All

I hope you can assist me with a case that is giving me challenges. I have a combobox with the following selections . . .

Select Reason list:
    ReasonList.Add("Please select")
    ReasonList.Add("Delivery")
    ReasonList.Add("Collection")
    ReasonList.Add("Meeting")
    ReasonList.Add("Just visiting")
    cmbReason.SetItems(ReasonList)

Now I want to be able to do something based on the selection using the Select statement...

Select statement:
    Select Case True
        Case Selected_Reason = "Delivery"
            Log("Delivery selected")
        Case Selected_Reason = "Collection"
            Log("Collection selected")
        Case Selected_Reason = "Meeting"
            Log("Meeting selected")
        Case Selected_Reason = "Just Visiting"
            Log("Just Visiting selected")
    End Select

Now when I select Delivery, Collection or Meeting, I can see the proper message on the log. However, when I select "Just visiting", the log does not show... Is it because it's 2 words? Even when I move the Selection list around and put "Just visiting" on top, same result.

How can I solve this?

Thanks
 
Solution
Take note on the Uppercase "V" and lowercase "v" in visiting.

Your Select-Case can be written as:
B4X:
    Select Selected_Reason
        Case "Delivery"
            Log("Delivery selected")
        Case "Collection"
            Log("Collection selected")
        Case "Meeting"
            Log("Meeting selected")
        Case "Just visiting"
            Log("Just visiting selected")
        Case Else
            Log(Selected_Reason)
    End Select

aeric

Expert
Licensed User
Longtime User
Take note on the Uppercase "V" and lowercase "v" in visiting.

Your Select-Case can be written as:
B4X:
    Select Selected_Reason
        Case "Delivery"
            Log("Delivery selected")
        Case "Collection"
            Log("Collection selected")
        Case "Meeting"
            Log("Meeting selected")
        Case "Just visiting"
            Log("Just visiting selected")
        Case Else
            Log(Selected_Reason)
    End Select
 
Upvote 0
Solution

walt61

Active Member
Licensed User
Longtime User
Hint: when using Select for a string value, I always use ToLowerCase, like:
B4X:
    Select Selected_Reason.ToLowerCase ' Added '.ToLowerCase'
        Case "delivery" ' All lowercase
            Log("Delivery selected")
        Case "collection" ' All lowercase
            Log("Collection selected")
        Case "meeting" ' All lowercase
            Log("Meeting selected")
        Case "just visiting" ' All lowercase
            Log("Just visiting selected")
        Case Else
            Log(Selected_Reason)
    End Select

That way, I don't have to worry about case mismatches (been there, done that).
 
Upvote 0
Top