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



Users browsing this thread: 1 Guest(s)