Sign in to follow this  
Followers 0
RosarioC

File questions.......(Tried to look everywhere, nothing.

7 posts in this topic

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:

Begining 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

Share this post


Link to post
Share on other sites



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:

Begining 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:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

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:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0