Sign in to follow this  
Followers 0
FireFox

_FileWriteLine

5 posts in this topic

Hi,

I try to make _FileWriteLine udf for write to some lines instead of one for each function call :lmao:

This is my example not working with my Added lines :

_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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites



Exists already a good function for this _FileWriteToLine(). :)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

@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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

@Andreik

:lmao: ... thats great example, I didnt think that way :think:

Thanks :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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