Jump to content

ReadLine...


 Share

Recommended Posts

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)
Link to comment
Share on other sites

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 B)

Link to comment
Share on other sites

It works... thanks B)

Glad that LxP could help... but why this:

; Write lines to file

FileWriteLine($file, "Line1")

FileWriteLine($file, "Line2" & @CRLF)

FileWriteLine($file, "Line3")

why not just:

; Write lines to file

FileWriteLine($file, "Line1")

FileWriteLine($file, "Line2")

FileWriteLine($file, "Line3")

just askin'

[size="1"][font="Arial"].[u].[/u][/font][/size]

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...