Emperor Posted June 3, 2006 Share Posted June 3, 2006 I seem to be having a problem trying to read a file from start to finish one character at a time. $File = FileOpen("Test.txt", 0) Dim $Var = 0 While $Var = 0 $Character = FileRead($File, 1) $Var = @error ;If @error = -1 Then ExitLoop ConsoleWrite($Character) WEnd FileClose($File) Exit This code works but still continues to print out rubbish even after getting all the info from the file. My Test.txt file contains the text "This is some text" and the above script prints out some extra weird characters at the end. Although it seems to work when I uncomment that one line that is not how I want to set my loop up. Link to comment Share on other sites More sharing options...
JoshDB Posted June 3, 2006 Share Posted June 3, 2006 (edited) $File = FileOpen("Test.txt", 0) Dim $Var = 0 While $Var = 0 $Character = FileRead($File, 1) If @error = -1 Then ExitLoop $Var = @error If @error = -1 Then ExitLoop ConsoleWrite($Character) WEnd FileClose($File) Exit There, you get to check if the FileRead failed and then you get to check if the $Var = @error failed. Your problem is that the If @error = -1 Then ExitLoop checks to see if the script is at the end of the file - Without it, it'll keep reading rubbish. P.S. - I don't see what $Var = @error does, you shouldn't need it. Edited June 3, 2006 by JoshDB Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite Link to comment Share on other sites More sharing options...
Emperor Posted June 3, 2006 Author Share Posted June 3, 2006 (edited) I know I could just check if FileRead failed but technically shouldn't this loop work? Edit: Wait just understood what you ment, don't worry im just an idiot, thanks for the help. Edited June 3, 2006 by Emperor 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