Page 1 of 1

eof() problem

Posted: Fri Sep 12, 2008 6:54 pm
by wmorton
Hi, I am accessing a text file with readfile() and then reading strings one by one which I am writing to another text file. However, the program seemingly runs forever, never getting out of the While/Wend section, as if there is no end to the original file:

Code: Select all

    While Eof(#ORIGINAL) = 0
      
      Repeat
        current_string$ = ReadString(#ORIGINAL)
        WriteStringN(#SHUFFLED, current_string$)
      Until current_string$ = "    <ITEM"
      
      position.f = ValF(RemoveString(ReadString(#ORIGINAL), "      POSITION "))
      length.f = ValF(RemoveString(ReadString(#ORIGINAL), "      LENGTH "))
      
      If counter = 0
        WriteStringN(#SHUFFLED, "      POSITION " + StrF(position.f))
        WriteStringN(#SHUFFLED, "      LENGTH " + StrF(length.f))
        new_position.f = prev_position.f + prev_length.f
        counter = 1
      Else
        WriteStringN(#SHUFFLED, "      POSITION " + StrF(new_position.f))
        WriteStringN(#SHUFFLED, "      LENGTH " + StrF(length.f))
        new_position.f = prev_position.f + prev_length.f + ValF(GetGadgetText(#SPACING))
      EndIf
      
      prev_position.f = new_position.f
      prev_length.f = length.f
      
    Wend
Any ideas what I'm doing wrong?

Thanks!

Posted: Fri Sep 12, 2008 7:12 pm
by byo
In my opinion, the While loop you're using is a little unsafe since you use ReadString many times during this one loop.

Posted: Fri Sep 12, 2008 7:37 pm
by Trond
Use the debugger and stop the program to see where it is stuck. I'm betting it's somewhere in this code:

Code: Select all

      Repeat 
        current_string$ = ReadString(#ORIGINAL) 
        WriteStringN(#SHUFFLED, current_string$) 
      Until current_string$ = "    <ITEM"