Skuller74 Posted November 30, 2005 Posted November 30, 2005 Hey, I'm new at AutoIt... so I havn't made anything special, so I'm just experimenting with easy things. So... when I execute this script, it outputs Failure... why? ;Open file $file = FileOpen("lines.txt", 2) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Write lines to file FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") ; Read line $text = FileReadLine($file, 3) ; Check if text is there If $text = "Line3" Then MsgBox(0, "Success", "Success! Line reads 'Line3'") Else MsgBox(0, "Failure", "Failure... Line does not read 'Line3'") EndIf FileClose($file)
LxP Posted November 30, 2005 Posted November 30, 2005 Possibly because you are attempting to open a file twice -- you need to close it before opening it under a new mode.
Skuller74 Posted November 30, 2005 Author Posted November 30, 2005 ah cool thanks ^^ so it should look like this... $file = FileOpen("lines.txt", 2) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") ; Closes file FileClose($file) ; Reopens file FileOpen("lines.txt", 0) $text = FileReadLine($file, 3) If $text = "Line3" Then MsgBox(0, "Success", "Success! Line reads 'Line3'") Else MsgBox(0, "Failure", "Failure... Line does not read 'Line3'") EndIf FileClose($file) It works... thanks
herewasplato Posted November 30, 2005 Posted November 30, 2005 It works... thanks Glad that LxP could help... but why this:; Write lines to fileFileWriteLine($file, "Line1")FileWriteLine($file, "Line2" & @CRLF)FileWriteLine($file, "Line3")why not just:; Write lines to fileFileWriteLine($file, "Line1")FileWriteLine($file, "Line2")FileWriteLine($file, "Line3")just askin' [size="1"][font="Arial"].[u].[/u][/font][/size]
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