RosarioC Posted April 9, 2010 Share Posted April 9, 2010 Hello, Now i'm sure you've heard these questions A MILLION TIMES, but i have tried to find somethingon it, even tried to look at the examples, not really getting it.....:-p. anyways, i have a file i created, i wrote text to it and it worked then i tried to write another text to it, nothing.......here it is: expandcollapse popupBegining of the file creation: $FileName = "\DataBase\Database.ext" $File = FileOpen($FileName,2) if $File then MsgBox(0,"File created" ,"QIGGADY!!") else MsgBox(0,"File not created","Error code: " & @error) endif the writing process: if FileExists($FileName) then $Write = FileWriteLine($FileName,"text") $Line2 = FileWriteLine($FileName,"text2") FileFlush($File) if $Line2 = 1 then MsgBox(0,"Line 2 written","QIGGIDY!!!") FileClose($fileName) endif if $Write = 1 then MsgBox(0,"This was a triumph, i'm making a note here; huge success","Data Written") else FileClose($fileName) MsgBox(0,"Can't write to file","" &$Write) endif else MsgBox(0,"File not found","" & $FileName) endif Chances are? i'm doing something horribly wrong which doesn't surprise me :-P Link to comment Share on other sites More sharing options...
doudou Posted April 9, 2010 Share Posted April 9, 2010 Hello, Now i'm sure you've heard these questions A MILLION TIMES, but i have tried to find somethingon it, even tried to look at the examples, not really getting it.....:-p. anyways, i have a file i created, i wrote text to it and it worked then i tried to write another text to it, nothing.......here it is: expandcollapse popupBegining of the file creation: $FileName = "\DataBase\Database.ext" $File = FileOpen($FileName,2) if $File then MsgBox(0,"File created" ,"QIGGADY!!") else MsgBox(0,"File not created","Error code: " & @error) endif the writing process: if FileExists($FileName) then $Write = FileWriteLine($FileName,"text") $Line2 = FileWriteLine($FileName,"text2") FileFlush($File) if $Line2 = 1 then MsgBox(0,"Line 2 written","QIGGIDY!!!") FileClose($fileName) endif if $Write = 1 then MsgBox(0,"This was a triumph, i'm making a note here; huge success","Data Written") else FileClose($fileName) MsgBox(0,"Can't write to file","" &$Write) endif else MsgBox(0,"File not found","" & $FileName) endif Chances are? i'm doing something horribly wrong which doesn't surprise me :-P If you bother to open the file with $File = FileOpen($FileName,2) so why don't you use the $File handle returned in further operations but $FileName? Try to replace $FileName => $File beneath FileOpen(). UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE Link to comment Share on other sites More sharing options...
ajag Posted April 9, 2010 Share Posted April 9, 2010 Hi RosarioC,from the help file (FileWriteLine):Note: Do not mix filehandles and filenames, i.e., don't FileOpen a file and then use a filename in this function. Either use filehandles or filenames in your routines, not both.That means if you use FileWriteLine with a filename as parameter #1 you do not have to open/close the file by hand!A-ay Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
RosarioC Posted April 9, 2010 Author Share Posted April 9, 2010 Hi RosarioC,from the help file (FileWriteLine):That means if you use FileWriteLine with a filename as parameter #1 you do not have to open/close the file by hand!A-aybut how would it know what mode the file is in? doesn't FileOpen set the mode? i think i saw a FileSetMode once in the help files.......seems to be gone. Link to comment Share on other sites More sharing options...
ajag Posted April 9, 2010 Share Posted April 9, 2010 (edited) Look to the help file: 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. However, filename will be created if it does not already exist. Using FileWriteLine with a filename as parameter the file will be opend and closed implizit. And if the file does not exist it will be created. So either use $filehandle = FileOpen("test.txt",1) FileWriteLine($filehandle, "a text line") FileClose($filehandle) OR use $filename = "test.txt" FileWriteLine($filename, "a text line") A-Jay Edited April 9, 2010 by ajag Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
doudou Posted April 9, 2010 Share Posted April 9, 2010 but how would it know what mode the file is in? doesn't FileOpen set the mode? i think i saw a FileSetMode once in the help files.......seems to be gone.DON'T USE $FileName!!! USE $File!!!Do you read only the latest post? UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE Link to comment Share on other sites More sharing options...
RosarioC Posted April 9, 2010 Author Share Posted April 9, 2010 DON'T USE $FileName!!! USE $File!!!Do you read only the latest post?oh......sorry, i thought i heard that u could use that in case you wanted to change the file extension,.....my bad, don't mean to seem like i'm expecting all the work from you guys... 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