Jump to content

_FileWriteToLine inside do until loop


Maani
 Share

Recommended Posts

hi there,

first of all thanks for creating a wonderful programing app. and offering help through the site.

as the topic says - i cant seem to use _filewritetoline func. inside a do until loop. am i doing something wrong or is it not supported ? here is a simple coding for testing purpose

#Include <File.au3>
FileOpen("testing.txt",1) ; to create a file
$i = 4
Do
_FileWriteToLine("testing.txt", 1, $i, 1) ; i want to overwrite the first line
$i = $i + 1
Until $i = 5

what is missing ?

regards.

Link to comment
Share on other sites

_FileWriteToLine() will open the file on it's own, so you need to remove the FileOpen() for it to work.

#Include <File.au3>
FileOpen("testing.txt",1); to create a file
FileClose("testing.txt"); to close the handle
$i = 4
 Do
 _FileWriteToLine("testing.txt", 1, $i, 1) ; i want to overwrite the first line
 $i = $i + 1
 Until $i = 5

the testing.txt file should contain 4 in it - but it's still empty

i also omitted fileopen and fileclose lines and placed an empty testing.txt file but still not writing

any idea ?

Link to comment
Share on other sites

You aren't using FileClose() properly there.

#Include <File.au3>
Local $hFile = FileOpen("testing.txt",1); to create a file
FileClose($hFile); to close the handle
$i = 4
 Do
 _FileWriteToLine("testing.txt", 1, $i, 1) ; i want to overwrite the first line
 $i = $i + 1
 Until $i = 5

still not working

can u please try it yourself once and for all

waiting ...

Link to comment
Share on other sites

I believe that the problem stems from the fact that $i is a number and not a string.

Test it for yourself.

$i = "4" ; This string will be written.
 Do
     _FileWriteToLine("testing.txt", 1, $i, 1)
     $i = $i + 1 ; Forces $i to be reinterpreted as a number.
 Until $i = 5

It's not the way I would do it, but I hope it gives you an idea.

Edited by czardas
Link to comment
Share on other sites

I believe that the problem stems from the fact that $i is a number and not a string.

Test it for yourself.

$i = "4" ; This string will be written.
 Do
     _FileWriteToLine("testing.txt", 1, $i, 1)
     $i = $i + 1 ; Forces $i to be reinterpreted as a number.
 Until $i = 5

It's not the way I would do it, but I hope it gives you an idea.

It worked.

i used to do programming at school in BASIC language, and as far as i remember for numeric values variable w/o strings were used where as "$" was used to define a string/non-numeric value. i = 1 ; i$ = "hello"

well anyway, the solution was simple but i learnt something.

Thank you very much for providing the solution in such a short time.

good day.

Link to comment
Share on other sites

Yeah that problem confused me a few times too. Perhaps the following code would be a more sensible solution. There are probably other ways that I am not aware of.

#Include <File.au3>
Local $hFile = FileOpen("testing.txt",1); to create a file
FileClose($hFile); to close the handle

$i = 4
 Do
     _FileWriteToLine("testing.txt", 1, ""&$i, 1) ; concatenate the number (with nothing) to produce a string.
     $i = $i + 1
 Until $i = 5
Edited by czardas
Link to comment
Share on other sites

Yeah that problem confused me a few times too. Perhaps the following code would be a more sensible solution. There are probably other ways that I am not aware of.

#Include <File.au3>
Local $hFile = FileOpen("testing.txt",1); to create a file
FileClose($hFile); to close the handle

$i = 4
 Do
     _FileWriteToLine("testing.txt", 1, ""&$i, 1) ; concatenate the number (with nothing) to produce a string.
     $i = $i + 1
 Until $i = 5

Bravo ! This is exactly what i needed because in my program the numeric value for $i is extracted from another source. Edited by Maani
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...