|
|
|||||||
I am looking at the open and readline functions on p. 53-54 of the KiXtart 2010 manual, and I don't understand why the code below is producing an endless loop. Mylist.txt contains only 1 line. Code: $datafile="c:\mylist.txt" If Open (1,"$datafile") = 0 $line = ReadLine(1) While @error = 0 $line = ReadLine(1) myfunction() Loop EndIf Exit Function myfunction() ? "My Function" EndFunction |
||||||||
|
|
|||||||
You are calling MyFunction, this function will set @error to 0 if it succeeds in displaying the text so While @error = 0 will always be true. Some other action that returns something else then 0 will end the loop. You might want to swap the Readline and MyFunction() that way you can also do stuff when it has read the first line. |
||||||||
|
|
|||||||
Thank you. That helps. |
||||||||
|
|
|||||||
Putting END at the end of my file is what I came up with, but I'm wondering if there is a more elegant way to do this? Code: $datafile="c:\mylist.txt" If Open (1,"$datafile") = 0 $line = ReadLine(1) While $line <> "END" myfunction() $line = ReadLine(1) Loop EndIf Exit Function myfunction() ? "ResetVariables" EndFunction |
||||||||
|
|
|||||||
A small example. Code: $datafile = "c:\mylist.txt" If Open(1, $datafile, 2) = 0 $line = ReadLine(1) While Not @ERROR ? "Reset variables" Sleep 2 $line = ReadLine(1) Loop EndIf Mylist.txt: Quote: Line1 Line2 Line3 |
||||||||
|
|
|||||||
To elaborate just a bit on Mart's suggestion, when you create a loop that's controlled by @ERROR being false, you MUST place the command or function that will set the error you are interested in LAST in the loop code. For example: Code: $Line = ReadLine(2) While Not @ERROR ; do this stuff until an error occurs ; stuff goes here to process $Line $Line = ReadLine(2) ; will set @ERROR when no more data is available (EOF Error) Loop Glenn |
||||||||
|
|
|||||||
Thank you again. |