Jump to content

Filereadline without handle problem


Recommended Posts

I try to use filereadline without use file open with handle but i have problem

This code dont work

FileOpen("test.txt", 0)

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine("test.txt")
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend

FileClose("test.txt")

This script read always only the first line from txt file and error set always to 0.

Also dont exit loop while wend.

If i use open function with handle and filereadline function with handle all is ok

any suggestions?

Edgar :)

Link to comment
Share on other sites

Why are you stuck on not using a file handle?

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Help says :

CODE
If no line number to read is given, the "next" line will be read. ("Next" for a newly opened file is initially the first line.)

If a filename is given rather than a file handle - the file will be opened and closed during the function call - for parsing large text files this will be much slower than using filehandles.

Edited by Inverted
Link to comment
Share on other sites

Why are you stuck on not using a file handle?

I always used to handle files since programmed in C, this was just a curiosity 'because in the help Autoit on write the indication that you can' use the functions files directly with the file name.

But they apparently do not work properly without use file handle

Edgar :)

Link to comment
Share on other sites

try this

$f=FileOpen("text.txt", 0)

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($f)
    If @error Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend

FileClose($f)

If no line number to read is given, the "next" line will be read. ("Next" for a newly opened file is initially the first line.)

BUT...

If a filename is given rather than a file handle - the file will be opened and closed during the function call - for parsing large text files this will be much slower than using filehandles.

you must read ALL the help file...

And you must use the handle returned by fileopen()

Edited by isolation
Link to comment
Share on other sites

try this

$f=FileOpen("text.txt", 0)

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($f)
    If @error Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend

FileClose($f)

BUT...

you must read ALL the help file...

And you must use the handle returned by fileopen()

Thanks for help

I know about use file handle , not problem, i use many time in autoit scripts.

Only i try to use readline function without handle and i have the problem but maybe becouse in loop the file will be opened and closed during the readline function call and maybe this make all time read only the first line from the file .....

Edgar :)

Link to comment
Share on other sites

  • Developers

Thanks for help

I know about use file handle , not problem, i use many time in autoit scripts.

Only i try to use readline function without handle and i have the problem but maybe becouse in loop the file will be opened and closed during the readline function call and maybe this make all time read only the first line from the file .....

Edgar :)

The FileOpen() in your examples does nothing for you. When using a FileReadLine() with a filename it will perform an FileOpen(), FileReadLine() and FileColse() in the background each time.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...