Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing against multiple elements at a time without select case
#1
Select Case lets you test against things like this: Case 1, 2, 3, 4, 5  Is there a way to use this kind of expression list with 'If'?  I'm trying to make a little program that builds sprite sheets from a list of image files, and I'm testing to see if the file name extension matches an image files.  Here's the Sub I'm working on.  It just builds a list of file names from the files listed in a text file. 

Code: (Select All)

Sub LoadFromTxt( txt_file$, names_list$() )
    ''load a list of file names from a txt file
    Dim fp& : fp& = Freefile
    Dim tmp$
    Dim count& : count& = 1
   
    Open txt_file$, For Input as fp&
        While Not EOF(fp&)
            Line Input fp&, tmp$
            tmp$ = LTrim$(RTrim$(tmp$))
            If tmp$ <> "" Then
                ''test for image suffix .*
                Select Case Mid$(tmp$, Len(tmp$) - 4, 4)
                    Case ".png",".bmp",".jpg",".tga", _
                    ".psd",".gif",".hdr",".pic",".pnm", _
                    ".pcx",".svg",".ico",".cur",".qoi"
                        names_list$(count&) = tmp$
                        count& = count& + 1
                    Case Else
                        Print "Unknown file type " + tmp$
                End Select
            End If
        Wend
    Close fp&
End Sub

I just feel like it would look better with a couple of 'If' statements instead, and was wondering if you could use expression lists with If the way you could Select Case.
Reply


Messages In This Thread
Testing against multiple elements at a time without select case - by CMR - 04-16-2025, 03:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question on determining time spent in area fistfullofnails 9 820 08-25-2025, 01:55 PM
Last Post: fistfullofnails
  Testing for program Install routine. Cross Platform Compatible. ahenry3068 8 1,158 05-20-2025, 11:19 AM
Last Post: SpriggsySpriggs
  how to get a file's modified date/time and size in bytes? madscijr 36 7,660 05-10-2025, 05:17 AM
Last Post: eoredson
  Hard time with hardware acceleration. Pete 8 985 03-21-2025, 11:29 PM
Last Post: Pete
  testing a number's quare root is an integer and casting to a value? madscijr 22 3,374 01-29-2025, 11:12 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)