FireFox Posted January 22, 2009 Posted January 22, 2009 Hi, I try to make _FileWriteLine udf for write to some lines instead of one for each function call This is my example not working with my Added lines : expandcollapse popup_FileWriteLine('test.txt', '3|4|5', 'test') Func _FileWriteLine($sFile, $iLine, $sText, $fOverWrite = 1) $sLine = StringSplit($iLine, '|') ;Added If $sLine[1] < 1 Then Return SetError(4, 0, 0) ;Added If Not IsString($sText) Then Return SetError(6, 0, 0) If $fOverWrite <> 0 And $fOverWrite <> 1 Then Return SetError(5, 0, 0) If Not FileExists($sFile) Then Return SetError(2, 0, 0) Local $filtxt = FileRead($sFile, FileGetSize($sFile)) $filtxt = StringSplit($filtxt, @CRLF, 1) If UBound($filtxt, 1) < $iLine Then Return SetError(1, 0, 0) Local $fil = FileOpen($sFile, 2) If $fil = -1 Then Return SetError(3, 0, 0) For $i = 1 To UBound($filtxt) - 1 MsgBox(64, 'Current line', $i) ;Added For $Line = 1 To UBound($sLine) - 1 ;Added MsgBox(64, 'Line to write', $iLine) ;Added If $i = $sLine[$Line] Then ;Added If $fOverWrite = 1 Then If $sText <> '' Then FileWrite($fil, $sText & @CRLF) Else FileWrite($fil, $sText) EndIf ElseIf $fOverWrite <> 1 Then FileWrite($fil, $sText & @CRLF) FileWrite($fil, $filtxt[$i] & @CRLF) EndIf ElseIf $i < UBound($filtxt, 1) - 1 Then FileWrite($fil, $filtxt[$i] & @CRLF) ElseIf $i = UBound($filtxt, 1) - 1 Then FileWrite($fil, $filtxt[$i]) EndIf Next ;Added Next FileClose($fil) Return 1 EndFunc ;==>_FileWriteLine Place test.txt file in script dir x x x x x Only 3,4,5 line should be replaced with test... Thanks for anyhelp. Cheers, FireFox.
Andreik Posted January 22, 2009 Posted January 22, 2009 Exists already a good function for this _FileWriteToLine().
FireFox Posted January 22, 2009 Author Posted January 22, 2009 @Andreik I try to make an udf on it (see parts of my code is same as _FileWriteToLine) but I want to call it for change multiple lines instead of one... Cheers, FireFox.
Andreik Posted January 22, 2009 Posted January 22, 2009 (edited) @Andreik I try to make an udf on it (see parts of my code is same as _FileWriteToLine) but I want to call it for change multiple lines instead of one... Cheers, FireFox.#include <File.au3> Func _FileWriteLine($sFile,$iLine,$sText,$fOverWrite = 0) $SPLIT = StringSplit($iLine,"|") If IsArray($SPLIT) Then For $INDEX = 1 To $SPLIT[0] _FileWriteToLine($sFile,$SPLIT[$INDEX],$sText,$fOverWrite) Next EndIf EndFunc Edited January 22, 2009 by Andreik
FireFox Posted January 22, 2009 Author Posted January 22, 2009 @Andreik ... thats great example, I didnt think that way Thanks Cheers, FireFox.
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