Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to format a While... Wend correctly?
#3
(02-26-2024, 04:20 AM)PhilOfPerth Wrote: Another simple one:
What's the best way to skip a data item when searching a file? (the number of items is not known, and the item lengths are varied). 
For example, to skip an item and jump to  a GetData line in this listing:

MyFile$="MyFile"            
Open MyFile$ For Input As #1
' put GetData: here?
            While Not EOF(1)
' or GetData: here?
                Input #1, data$ 
                If Len(data$) <> 5 Then 
                  GoTo GetData
                else
                  DealWithIt
                End If
' or GetData: here
            Wend
Close

Forgetting our "phobias" about GoTo for now,
If the GetData  point is before the While statement,  will this create another loop, and leave the first one unresolved?
If it's just after the While statement, does whe While restart input at the beginning of the file?
Is the position just before the Wend the correct place?

A Goto in the following scenario, I am very comfortable with that.  It stays within the loop, and it is a GOTO with close proximity, so easy to see what is going on.

Code: (Select All)
MyFile$="MyFile"            
Open MyFile$ For Input As #1
            While Not EOF(1)
                Input #1, data$ 
                If Len(data$) <> 5 Then 
                  GoTo [b]GetData[/b]
                else
                  DealWithIt
                End If
' [b]GetData:[/b] here
            Wend
Close
Reply


Messages In This Thread
RE: How to format a While... Wend correctly? - by CharlieJV - 02-26-2024, 01:56 PM



Users browsing this thread: 17 Guest(s)