onestcoder Posted September 21, 2008 Share Posted September 21, 2008 (edited) I'm trying to add text to the end of line one of a text file. I want to be about to write to the same line multiple times without deleting the previous text, by append the new text to the end of it. I'm willing to use an ini file if needed. Ultimately i want to write a list to a text file that I can call into a combo box in another program. Edited September 21, 2008 by onestcoder Need a website: http://www.iconixmarketing.com Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 (edited) I'm trying to add text to the end of line one of a text file. I want to be about to write to the same line multiple times without deleting the previous text, by append the new text to the end of it. I'm willing to use an ini file if needed. Ultimately i want to write a list to a text file that I can call into a combo box in another program. Try this: #include <File.au3> Func _FileAppendToLine($PATH,$LINE,$TEXT) $FILE = FileOpen($PATH,0) $TEMP_LINE = FileReadLine($FILE,$LINE) FileClose($FILE) _FileWriteToLine($PATH,$LINE,$TEMP_LINE & $TEXT,1) EndFunc $PATH = @ScriptDir & "\MyFile.txt" _FileAppendToLine($PATH,3,"New Text") Edited September 21, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rasim Posted September 21, 2008 Share Posted September 21, 2008 AndreikWhy not just:#include <File.au3> $sFile = "c:\test.txt" _FileWriteToLine($sFile, 2, "New string", 0) ;If set to 1 will overwrite the old line. If set to 0 will not overwrite Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 Andreik Why not just: #include <File.au3> $sFile = "c:\test.txt" _FileWriteToLine($sFile, 2, "New string", 0) ;If set to 1 will overwrite the old line. If set to 0 will not overwrite For example: Test.txt LINE1 LINE2 LINE3 If you use your code will be: LINE1 NewString LINE2 LINE3 And onestcoder want to write the same line (in his case the last line). When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rasim Posted September 21, 2008 Share Posted September 21, 2008 AndreikOK, now I understand. Your example good, but not for a big file, because the FileReadLine() function always count strings from first string _FileAppendToLine("c:\test.txt", 3, "New Text") Func _FileAppendToLine($sFile, $sLine, $sString) Local $iRead, $aString, $iResult, $hFile, $i $iRead = FileRead($sFile) $aString = StringSplit(StringStripCR($iRead), @LF) If $aString[0] < $sLine Then Return SetError(1, 0, 0) $aString[$sLine] &= $sString For $i = 1 To $aString[0] $iResult &= $aString[$i] & @CRLF Next $hFile = FileOpen($sFile, 2) FileWrite($hFile, $iResult) FileClose($hFile) EndFunc ;==>_FileAppendToLine Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 Andreik OK, now I understand. Your example good, but not for a big file, because the FileReadLine() function always count strings from first string _FileAppendToLine("c:\test.txt", 3, "New Text") Func _FileAppendToLine($sFile, $sLine, $sString) Local $iRead, $aString, $iResult, $hFile, $i $iRead = FileRead($sFile) $aString = StringSplit(StringStripCR($iRead), @LF) If $aString[0] < $sLine Then Return SetError(1, 0, 0) $aString[$sLine] &= $sString For $i = 1 To $aString[0] $iResult &= $aString[$i] & @CRLF Next $hFile = FileOpen($sFile, 2) FileWrite($hFile, $iResult) FileClose($hFile) EndFunc ;==>_FileAppendToLine Your code work fine. Just edit _FileAppendToLine("C:\test.txt", 3, "New Text"). >_< When the words fail... music speaks. Link to comment Share on other sites More sharing options...
onestcoder Posted September 21, 2008 Author Share Posted September 21, 2008 (edited) THAT IS AWESOME GUYS!!!!! Thank you. FYI: I'm writing a program were I have a combo box "Customer's Name". The combo box gets it's content from a text file I manually wrote the customers name's in (ex: John Marks|Jane Marks....) Then I added to the file menu "Add New Customer" which I want to open the text file and add the customer's name to the list, thus adding them to the combo box list. Thank for the help When the program is complete i plan to add it the the examples forum. Edited September 21, 2008 by onestcoder Need a website: http://www.iconixmarketing.com Link to comment Share on other sites More sharing options...
Valuater Posted September 21, 2008 Share Posted September 21, 2008 Why not this.... it's been passed the review and is an included UDF #include <File.au3> ;Example: Write to line 3 of c:\test.txt REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1) ;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my insertion", 0) .... straight from help 8) Link to comment Share on other sites More sharing options...
Valuater Posted September 21, 2008 Share Posted September 21, 2008 (edited) THAT IS AWESOME GUYS!!!!! Thank you.FYI: I'm writing a program were I have a combo box "Customer's Name". The combo box gets it's content from a text file I manually wrote the customers name's in (ex: John Marks|Jane Marks....) Then I added to the file menu "Add New Customer" which I want to open the text file and add the customer's name to the list, thus adding them to the combo box list. Thank for the help When the program is complete i plan to add it the the examples forum.might want to take a look at this, it does what you are after, but uses a listview to show other info for the customer too.Located here.............http://www.autoitscript.com/forum/index.ph...st&p=2820678) Edited September 21, 2008 by Valuater Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 Why not this.... it's been passed the review and is an included UDF #include <File.au3> ;Example: Write to line 3 of c:\test.txt REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1) ;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my insertion", 0) .... straight from help 8)Because "my replacement for line 3" and "my insertion" will not be on the same line. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
onestcoder Posted September 22, 2008 Author Share Posted September 22, 2008 Thanks Valuater, for the heads up on EZ track. I will give it a look over. Need a website: http://www.iconixmarketing.com 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