Maani Posted January 31, 2010 Posted January 31, 2010 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.
Maani Posted January 31, 2010 Author Posted January 31, 2010 _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 ?
Maani Posted January 31, 2010 Author Posted January 31, 2010 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 ...
czardas Posted January 31, 2010 Posted January 31, 2010 (edited) 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 January 31, 2010 by czardas operator64 ArrayWorkshop
Maani Posted January 31, 2010 Author Posted January 31, 2010 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.
czardas Posted January 31, 2010 Posted January 31, 2010 (edited) 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 January 31, 2010 by czardas operator64 ArrayWorkshop
Maani Posted January 31, 2010 Author Posted January 31, 2010 (edited) 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 January 31, 2010 by Maani
czardas Posted February 1, 2010 Posted February 1, 2010 $i = 4 Do _FileWriteToLine("testing.txt", 1, String($i), 1) $i = $i + 1 Until $i = 5 Nobody picked up on this. I should have figured it out too. lol operator64 ArrayWorkshop
Maani Posted February 2, 2010 Author Posted February 2, 2010 $i = 4 Do _FileWriteToLine("testing.txt", 1, String($i), 1) $i = $i + 1 Until $i = 5 Nobody picked up on this. I should have figured it out too. lol I never knew about this function .. good find.
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