Jump to content
Sign in to follow this  
zax

Filewritetoline to vb.net

Recommended Posts

zax

anyway to convert this function to vb.net? since this udf is not in AutoItX3Lib.dll.

Func _FileWriteToLine($sFile, $iLine, $sText, $fOverWrite = 0)
    If $iLine <= 0 Then
        SetError(4)
        Return 0
    EndIf
    If Not IsString($sText) Then
        SetError(6)
        Return 0
    EndIf
    If $fOverWrite <> 0 And $fOverWrite <> 1 Then
        SetError(5)
        Return 0
    EndIf
    If Not FileExists($sFile) Then
        SetError(2)
        Return 0
    EndIf
    Local $filtxt = FileRead($sFile, FileGetSize($sFile))
    $filtxt = StringSplit($filtxt, @CRLF, 1)
    If UBound($filtxt, 1) < $iLine Then
        SetError(1)
        Return 0
    EndIf
    Local $fil = FileOpen($sFile, 2)
    If $fil = -1 Then
        SetError(3)
        Return 0
    EndIf
    For $i = 1 To UBound($filtxt) - 1
        If $i = $iLine Then
            If $fOverWrite = 1 Then
                If $sText <> '' Then
                    FileWrite($fil, $sText & @CRLF)
                Else
                    FileWrite($fil, $sText)
                EndIf
            EndIf
            If $fOverWrite = 0 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
    FileClose($fil)
    Return 1
EndFunc ;==>_FileWriteToLine
Edited by zax

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  

×