Select statements

francoisg

Active Member
Licensed User
Longtime User
When I do something like the code below, the select statement works up to the point of about 3 items. If I add more, the items after 3 is not recognized anymore (ie. it skips the select statement for example for ".jpg"). Any ideas why (B4A version 2.52)???

Select fileExt
Case ".txt": ' *** Text files ...
Case ".htm": ' *** HTML files ...
Case ".html":
Case ".png": ' *** Images files ...
Case ".jpg":
' *** Do something with file ...
Case ".mp3": ' Audio files ...
Case ".wma":
' *** Do something with audio file ...
End Select
 

francoisg

Active Member
Licensed User
Longtime User
Cool! I see that you don't need the colons ... funny ...

Anyway, I'm doing the following and it STILL does not work (The code below seems to skip even the "else" part for ".txt" for instance, where it should log "other"):

fileExt = ".txt"
Select fileExt
Case ".pdf"
Log("PDF")
Case ".url" ' *** URL ...
Case ".txt" ' *** Text files ...
Case ".htm" ' *** HTML files ...
Case ".html"
Case ".png" ' *** Images files ...
Case ".jpg"
Log("Other")
Case Else
Log("Invalid file type!!!")
End Select
 
Last edited:

francoisg

Active Member
Licensed User
Longtime User
Still not working ....

You set fileExt = ".txt"
So it finds Case ".txt" and scips all others.
That's normal behaviour.

Best regards.

Nope, it does NOT find ".txt" - it skips it for the given code, in fact it seems to even skip the "Case Else" part! For other values (".jpg" for instance) it seems to work... This code is used in a class (if that makes any difference) and it does not work as it should!

If I include code right underneath the Case ".txt" part, it finds ".txt" and executes the code ...
 

francoisg

Active Member
Licensed User
Longtime User
Put the following code into an empty project and run (uncomment code under Case ".txt" to make it "work":

Activity.Color = Colors.Red

Dim s As String = ".txt"
Dim b As Boolean = False
Select s
Case ".txt"
' Uncomment the following 2 lines to make it work!
'Log(".txt selected!")
'b = True
Case "a"
Case "b"
Case "c"
Case "d"
Case "e"
Case "f"
Case "g"
Case "h"
Case "i"
Case "j"
Log("it works!")
b = True
Case Else
Log("Case Else")
End Select
If Not (b) Then Log("skipped code!")
 

Stulish

Active Member
Licensed User
Longtime User
Once the Case has found the correct check as equal to true, in this case Case ".txt", then it executes the code until it gets to the next Case event and will then not execute the code until it gets to the end select statement, after this it will continue executing code in a linear type manner.

Thus is the case = ".txt" then you need to un-comment the b=True within the case ".txt" routine for it not to display "skipped code!".

not sure if i have explained it very well :(

Stu
 

agraham

Expert
Licensed User
Longtime User
Thus is the case = ".txt" then you need to un-comment the b=True within the case ".txt" routine for it not to display "skipped code!".Stu
That is correct and is my expected behaviour. Did you note my comment "Case does not drop through if that is what you are expecting". With your code commented as posted you would only get b = True executed if s= "j".
 

francoisg

Active Member
Licensed User
Longtime User
My mistake, I was expecting the case statements to fall through ...
I will just have to code it a bit differently ...

Thank you for all the replies (cleared this point for me)!
 
Last edited:
Top