Edgar0024 Posted January 30, 2009 Share Posted January 30, 2009 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 More sharing options...
SpookMeister Posted January 30, 2009 Share Posted January 30, 2009 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 More sharing options...
Inverted Posted January 30, 2009 Share Posted January 30, 2009 (edited) Help says : CODEIf 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 January 30, 2009 by Inverted Link to comment Share on other sites More sharing options...
Edgar0024 Posted January 30, 2009 Author Share Posted January 30, 2009 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 handleEdgar Link to comment Share on other sites More sharing options...
Inverted Posted January 30, 2009 Share Posted January 30, 2009 No, apparently you didn't read the command description properly. If you still don't understand I'll post an example. It's really simple, though. Link to comment Share on other sites More sharing options...
isolation Posted January 30, 2009 Share Posted January 30, 2009 (edited) 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 January 30, 2009 by isolation Link to comment Share on other sites More sharing options...
Edgar0024 Posted January 30, 2009 Author Share Posted January 30, 2009 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 More sharing options...
Developers Jos Posted January 30, 2009 Developers Share Posted January 30, 2009 (edited) Thanks for helpI 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 January 30, 2009 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 More sharing options...
isolation Posted January 30, 2009 Share Posted January 30, 2009 if you don't want to use the handle retrived from fileopen() you must use a "For" because what have written Jos is correct.. every loop the counter restarts from 0 so autoit reads always the first line Link to comment Share on other sites More sharing options...
Developers Jos Posted January 30, 2009 Developers Share Posted January 30, 2009 ..because what have written Jos is correct..Thanks 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now