Jump to content
Sign in to follow this  
JayJay

End Of File not detected

Recommended Posts

JayJay

I've got a program doing what I want it to do, except that it does not detect the end of file when reading.

The idea is simple: Read line from inputfile, if not at the end_of_file, write it to outputfile. It's just that I can't get it to work. muttley

If I delete these lines, the program works. If I keep these, it keeps writing empty lines to the new file.

I've copied this from the documentation:

While 1
    $LineRead = FileReadLine($FileHandleOld)
    If @error = -1 Then ExitLoop
    FileWriteLine($FileHandleNew, $LineRead)
WEnd

I've tried this because it has the condition in the loop:

$LineRead = FileReadLine($FileHandleOld)
While @error <> -1  
    FileWriteLine($FileHandleNew, $LineRead)
    $LineRead = StringStripWS(FileReadLine($FileHandleOld),3)
WEnd

Just for testing this, I've written a small program that just reads a line from "inputfile.txt" and writes it to "outputfile.txt"

Dim $FileNameOld = "inputfile.txt"                                      ; file name to open, needs an input box
Dim $FileHandleOld = ""                                                     ; Handle for old filename
Dim $FileNameNew = "outputfile.txt"                                         ; file name to write, same name as file to open with _new added to it
Dim $FileHandleNew = ""                                                     ; Handle for new filename

Dim $LineRead = ""

$FileHandleOld = FileOpen($FileNameOld,0)                                   ; Open old file for reading
$FileHandleNew = FileOpen($FileNameNew,2)                                   ; Open new file for writing, empty file if it exists

While 1
    $LineRead = StringStripWS(FileReadLine($FileHandleOld),3)
    If @error = -1 Then ExitLoop
    FileWriteLine($FileHandleNew, $LineRead)
WEnd
FileClose($FileHandleOld)
FileClose($FileHandleNew)

; end of program

It does't work like it should. I have to right-click the tray icon to stop the program, and it keeps writing empty lines to the outputfile.

I'm using Windows Vista Home (in Dutch language) and I have the latest version of autoit (not the beta)

Edited by JayJay

Share this post


Link to post
Share on other sites
ProgAndy

$LineRead = StringStripWS(FileReadLine($FileHandleOld),3)
If @error = -1 Then ExitLoop

... You check the error from the last executed function, but this is StringStripWS. You have to split the command:

$LineRead = FileReadLine($FileHandleOld)
If @error = -1 Then ExitLoop
$LineRead = StringStripWS($LineRead,3)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
JayJay

... You check the error from the last executed function, but this is StringStripWS. You have to split the command:

Thank you. I hadn't thought about that stripping of white spaces

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×