A case with… Select Case

What is wrong with this code:


// ********** ********** ********** **********
// Add only file matching image extension
// Start with the list of items to ignore
// Then Check what I want and store if OK
Select Case img_FI
  // Ignore Cases
Case img_FI.IsAlias
Case img_FI.IsFolder
Case Not img_FI.Visible
Case img_FI.Name.Left(1) = "."
  
  // Take Cases
Case img_FI.Name.InStr(".gif.jpg.jpeg.pdf.png.tif.tiff.webp") > 0
  Names_List.Add img_FI.Name
  
Else
  // Let these in the Vaults
End Select

The error lies in the Select Case Img_FI line
The errors from the Debuger:

Another Select Case taken from the LR show no error once I commented this one.

I even removed the comments, and use only End (instead of End Select)

Sequoia / 2024r4.1 (too)

You probably want to start it with Select Case True.

4 Likes

Or Xojo is playing with Me.

I Commented the Select Case lines and add it using an If …/… Else …/… End If block.
I add two System.DebugLog with the name of the tested file (and append " - Rejected" on the Else line).
None was selected !

I try to sleep now.

Compiles Now, but nothing is added into pNames_List() as in the if block…

Good night and Happy New Year.

Select Case img_FI
  // Ignore Cases
Case img_FI.IsAlias
Case img_FI.IsFolder
Case Not img_FI.Visible
…

As Eric points out, you probably want
Select Case True

What you are essentially writing is

Select Case img_FI
  // Ignore Cases
Case img_FI.IsAlias // Is it true that: img_FI.IsAlias = img_FI
Case img_FI.IsFolder // Is it true that: img_FI.IsFolder = img_FI
Case Not img_FI.Visible // Is it true that: Not (img_FI.Visible) = img_FI
…

Of course, none of these things are true and, in fact, asking if they are equal does not really make any sense.

1 Like

The root problem with nothing selected is probably down to this

img_FI.Name.InStr(“.gif.jpg.jpeg.pdf.png.tif.tiff.webp”) > 0

since you cannot check for multiple things being present at once.
The only kind of file that would match this would be one with all 8 extensions

something.gif.jpg.jpeg.pdf.png.tif.tiff.webp

So having eliminated the folders, aliases, and invisibles

select case true
Case img_FI.Name.InStr(".gif") > 0
  Names_List.Add img_FI.Name
Case img_FI.Name.InStr(".jpg") > 0
  Names_List.Add img_FI.Name
Case img_FI.Name.InStr(".jpeg") > 0
  Names_List.Add img_FI.Name
Case img_FI.Name.InStr(".pdf") > 0
  Names_List.Add img_FI.Name
Case img_FI.Name.InStr(".png") > 0
  Names_List.Add img_FI.Name
Case img_FI.Name.InStr(".png") > 0
  Names_List.Add img_FI.Name
//etc
end select
Select Case True
Case // Takes cases

??? is this just a way to include a comment?

haha. Nope. That was a bit of text I didnt realise was still lying around before I clicked OK.
Editted it out.

Var f As FolderItem = SpecialFolder.Desktop.Child("Virtual Desktop.txt")

Select Case f.Extension.Lowercase
Case "txt","jpg"
  System.DebugLog f.Extension
Case Else
End Select
2 Likes

I guess you wanted to process something like this:

// valid file?
If img_FI <> Nil And             _
  Not img_FI.IsAlias And         _
  Not img_FI.IsFolder And        _
  img_FI.Visible And             _
  img_FI.Name.Left(1) <> "." And _
  img_FI.Exists Then               
  
  // proper image?
  Const imgExts As String = ".gif.jpg.jpeg.pdf.png.tif.tiff.webp."
  If imgExts.IndexOf("."+img_FI.Extension.Lowercase+".") >= 0 Then
    
    // DoWhatever(img_FI)             
    
  Else // Vault cases
    
    // Vault(img_FI)                            
    
  End

End

That’s it: in my mind, it checked if the current file extension is one from these, if YES !, it store it, else, go to test the next file.

At a moment, I reload Xojo / Project to verify I used Greater Than 0 (because sometimes I use Less Than instead)…

I will install Rick advice (looks nice too :wink: ).

Thank you all.

It is possible to use if / elseif

If ( XXX ) then
// make something
ElseIf ( YYY ) then
// make something
ElseIf ( ZZZ ) then
// make something
else
// make something
end if

Rick already sent an If (better as usual) solution.

And it worked fine.

Next step: fine tune arrow keys
If possible
Rename Reprint with some data from original
Move found Ooriginal(s) into a temp folder)

and some more ides that can comes later.