Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with EOF not working 2

Status
Not open for further replies.

Jasen

IS-IT--Management
May 1, 2002
435
0
0
US
Here's my sample code:
Code:
            Open myfile For Input As #1
            
            Do Until EOF(1)
                DoEvents
operation:
                Line Input #1, Linebuffer
                If Left(Linebuffer, 9) = "OPERATION" Then
                    Line Input #1, Linebuffer
                    operation = Left$(Linebuffer, 15)
                    GoTo part:
                Else
                    GoTo operation:
                End If
part:
                Line Input #1, Linebuffer
                If Left$(Linebuffer, 4) = "PART" Then
                    Line Input #1, Linebuffer
                    part = Left$(Linebuffer, 8)
                    GoTo readings:
                Else
                    GoTo part:
                End If
readings:
                Dim found1 As Integer
                Line Input #1, Linebuffer
                If Left$(Linebuffer, 4) = "0000" Then
                    Fieldname = Mid$(Linebuffer, 6, 15)
                    reading = Mid$(Linebuffer, 74, 7)
                    txtDisplay.Text = txtDisplay.Text & Trim$(operation) & ", " & Trim$(part) & ", " & Trim$(Fieldname) & ", " & _
                                      Trim$(reading) & Chr(13)
                    found1 = found1 + 1
                    GoTo readings:
                Else
                    If found1 = 0 Then
                        GoTo readings
                    End If
                End If
            Loop

It just parses text files, that are partially fixed length, and partially not. I'm sure it's clunky, but it works, except for the fact that it still attempts to read past the end of the file, throwing an error. The EOF/loop isn't catching it for some reason. Is there an apparent reason why? Does EOF not work right when I go inside the If/then's?

________
Remember, you're unique... just like everyone else.
 
ah, that would do it. I assumed that EOF was checking the file's state continuously, not just once per loop.
Sticking a couple "If EOF(1)"'s inside the loop fixed the problem, thanks much.
 
No one is going to comment on the Goto statements?


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Who am I to say anything, when I throw those bad boys in whenever I need a quick fix and the code is just too much myself. If the man wants to use goto, let him use goto. It's not the best, it's not the cleanest, it's not recommended, but it works for him.
-Max
 
I know the goto's are clumsy. Was the easiest way to do what I wanted at the time though. If anyone wants to show me a better alternative that does the same function there, I'm always eager to learn.
 
I would recommend using the Do Until loops, for example:

Code:
'run until operation found
Do  = "OPERATION" Then
   'get line
   Line Input #1, Linebuffer
Loop Until Left(Linebuffer, 9) = "OPERATION"
operation = Left$(Linebuffer, 15)

-Max
 
Ok since I opened my mouth here a shot at what you are trying to do :)
Code:
Do Until EOF(1)
    DoEvents
    Line Input #1, LineBuffer
    If Left(LineBuffer, 9) = "OPERATION" Then
        Line Input #1, LineBuffer
        operation = Left$(LineBuffer, 15)
        Do Until EOF(1)
            Line Input #1, LineBuffer
            If Left$(LineBuffer, 4) = "PART" Then
                part = Left$(LineBuffer, 8)
                Do Until EOF(1)
                    Line Input #1, LineBuffer
                    If Left$(LineBuffer, 4) = "0000" Then
                        FieldName = Mid$(LineBuffer, 6, 15)
                        Reading = Mid$(LineBuffer, 74, 7)
                        txtdisplay.Text = txtdisplay.Text & Trim$(operation) & ", " & Trim$(part) & ", " & Trim$(FieldName) & ", " & _
                                          Trim$(Reading) & Chr(13)
                    End If
                Loop
            End If
        Loop
    End If
Loop


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I sometimes use goto when I get irritated at VB's lack of a "preemptively go to the next iteration of the loop" functionality. (Unless there is such a thing and I don't know about it?)

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top