_FileWriteFromArray Probleme

  • Hallo,

    ich möchte gerne ein Array (mehrere Daten)
    in eine Datei speichern.
    Erhalte Fehlermeldungen... klappt irgendwie nicht.

    Hier mal die Infos:

    [autoit]


    #include <Array.au3>
    #include<File.au3>
    Global $sFile = @ScriptDir & "\ilse.txt"

    [/autoit]

    Ich lasse mir im Script das Array anzeigen
    das als File gespeichert werden soll:

    [autoit]


    _ArrayDisplay($aTexte)

    [/autoit]

    bis hierhin ist alles ok
    sieht so aus:

    autoit.de/wcf/attachment/16127/

    dann habe ich mit _FileWriteFromArray alles mögliche probiert

    [autoit]


    _FileWriteFromArray($sFile, $aTexte)

    [/autoit]

    aber das klappt alles nicht


    Grüße
    Ilse ;)

  • Hallo Tweaky,

    danke für den Hinweis.

    Ich habe die Funktion eingebaut, aber die Textdatei bleibt leer?

    Mein Aufruf sieht so aus:

    [autoit]


    _FileWriteFromArray2D($sFile, $aTexte,0)

    [/autoit]


    Grüße
    Ilse :(

    Einmal editiert, zuletzt von Ilse (6. August 2012 um 15:51)

  • Wenn ich das probiere

    [autoit]


    $Test = _FileWriteFromArray2D($sFile, $aTexte,1)

    [/autoit][autoit][/autoit][autoit]

    MsgBox(0,"",$test)

    [/autoit]

    erhalte ich -1

    Hier mal die Datei v. Bugfix

    Spoiler anzeigen
    [autoit]


    ;==========================================================================================================================================
    ; Function: _FileWriteFromArray2D($FILEPATH, $ARRAY [, $iROWstart=0 [, $iROWend=0 [, $iCOLstart=0 [, $iCOLend=0 [, $DELIM='|']]]]])
    ;
    ; Description: Write 1D/2D array to file, 2D with delimiter between every entry
    ;
    ; Parameter(s): $FILEPATH - path/filename of the file to be write
    ; $ARRAY - array to write from
    ; optional $iROWstart - start row-index, default 0
    ; optional $iROWend - end row-index, default Ubound(array)-1
    ; optional $iCOLstart - start column-index, default 0
    ; optional $iCOLend - end column-index, default Ubound(array,2)-1
    ; optional $DELIM - delimiter for 2D-array entries, default '|'
    ;
    ; Requirement(s): None
    ;
    ; Return Value(s): On Success - Returns -1
    ; On Failure - Returns 0 and sets @error = 1 (given array is'nt array); @error = 2 (unable to open filepath)
    ;
    ; Note: If $iROWstart > $iROWend or $iCOLstart > $iCOLend the values will be swapped among
    ;
    ; Author(s): BugFix ( [email='bugfix@autoit.de'][/email] )
    ;==========================================================================================================================================
    Func _FileWriteFromArray2D($FILEPATH, $ARRAY, $iROWstart=0, $iROWend=0, $iCOLstart=0, $iCOLend=0, $DELIM='|')
    If Not IsArray($ARRAY) Then
    SetError(1)
    Return 0
    EndIf
    Local $Ubound = UBound($ARRAY)
    If $iROWend = 0 Then $iROWend = $Ubound-1
    Local $fh = FileOpen($FILEPATH, 2)
    If $fh = -1 Then
    SetError(2)
    Return 0
    EndIf
    Select
    Case $iROWstart < 0 Or $iROWstart > $Ubound-1
    $iROWstart = 0
    ContinueCase
    Case $iROWend < 0 Or $iROWend > $Ubound-1
    $iROWend = $Ubound-1
    ContinueCase
    Case $iROWstart > $iROWend
    $tmp = $iROWstart
    $iROWstart = $iROWend
    $iROWend = $tmp
    EndSelect
    Local $Ubound2nd = UBound($ARRAY, 2)
    If @error = 2 Then
    For $i = $iROWstart To $iROWend
    FileWriteLine($fh, $ARRAY[$i])
    Next
    Else
    If $iCOLend = 0 Then $iCOLend = $Ubound2nd-1
    Select
    Case $iCOLstart < 0 Or $iCOLstart > $Ubound2nd-1
    $iCOLstart = 0
    ContinueCase
    Case $iCOLend < 0 Or $iCOLend > $Ubound2nd-1
    $iCOLend = $Ubound2nd-1
    ContinueCase
    Case $iCOLstart > $iCOLend
    $tmp = $iCOLstart
    $iCOLstart = $iCOLend
    $iCOLend = $tmp
    EndSelect
    For $i = $iROWstart To $iROWend
    $tmp = ''
    For $k = $iCOLstart To $iCOLend
    If $k < $iCOLend Then
    $tmp &= $ARRAY[$i][$k] & $DELIM
    Else
    $tmp &= $ARRAY[$i][$k]
    EndIf
    Next
    FileWriteLine($fh, $tmp)
    Next
    EndIf
    FileClose($fh)
    Return -1
    EndFunc ;==>_FileWriteFromArray2D

    [/autoit]

    Einmal editiert, zuletzt von Ilse (6. August 2012 um 16:25)

  • Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include<File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $sFile = @ScriptDir & "\ilse.txt"
    Global $aTexte[3][5]
    FOr $i = 0 To Ubound($aTexte) -1
    For $k = 0 To UBound($aTexte, 2) -1
    $aTexte[$i][$k] = Random(1,100,1)
    Next
    Next
    _arraydisplay($aTexte)
    _FileWriteFromArray2D($sFile, $aTexte,0)
    $read = FileRead($sFile)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $read = ' & $read & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;==========================================================================================================================================
    ; Function: _FileWriteFromArray2D($FILEPATH, $ARRAY [, $iROWstart=0 [, $iROWend=0 [, $iCOLstart=0 [, $iCOLend=0 [, $DELIM='|']]]]])
    ;
    ; Description: Write 1D/2D array to file, 2D with delimiter between every entry
    ;
    ; Parameter(s): $FILEPATH - path/filename of the file to be write
    ; $ARRAY - array to write from
    ; optional $iROWstart - start row-index, default 0
    ; optional $iROWend - end row-index, default Ubound(array)-1
    ; optional $iCOLstart - start column-index, default 0
    ; optional $iCOLend - end column-index, default Ubound(array,2)-1
    ; optional $DELIM - delimiter for 2D-array entries, default '|'
    ;
    ; Requirement(s): None
    ;
    ; Return Value(s): On Success - Returns -1
    ; On Failure - Returns 0 and sets @error = 1 (given array is'nt array); @error = 2 (unable to open filepath)
    ;
    ; Note: If $iROWstart > $iROWend or $iCOLstart > $iCOLend the values will be swapped among
    ;
    ; Author(s): BugFix ( [email='bugfix@autoit.de'][/email] )
    ;==========================================================================================================================================
    Func _FileWriteFromArray2D($FILEPATH, $ARRAY, $iROWstart=0, $iROWend=0, $iCOLstart=0, $iCOLend=0, $DELIM='|')
    If Not IsArray($ARRAY) Then
    SetError(1)
    Return 0
    EndIf
    Local $Ubound = UBound($ARRAY)
    If $iROWend = 0 Then $iROWend = $Ubound-1
    Local $fh = FileOpen($FILEPATH, 2)
    If $fh = -1 Then
    SetError(2)
    Return 0
    EndIf
    Select
    Case $iROWstart < 0 Or $iROWstart > $Ubound-1
    $iROWstart = 0
    ContinueCase
    Case $iROWend < 0 Or $iROWend > $Ubound-1
    $iROWend = $Ubound-1
    ContinueCase
    Case $iROWstart > $iROWend
    $tmp = $iROWstart
    $iROWstart = $iROWend
    $iROWend = $tmp
    EndSelect
    Local $Ubound2nd = UBound($ARRAY, 2)
    If @error = 2 Then
    For $i = $iROWstart To $iROWend
    FileWriteLine($fh, $ARRAY[$i])
    Next
    Else
    If $iCOLend = 0 Then $iCOLend = $Ubound2nd-1
    Select
    Case $iCOLstart < 0 Or $iCOLstart > $Ubound2nd-1
    $iCOLstart = 0
    ContinueCase
    Case $iCOLend < 0 Or $iCOLend > $Ubound2nd-1
    $iCOLend = $Ubound2nd-1
    ContinueCase
    Case $iCOLstart > $iCOLend
    $tmp = $iCOLstart
    $iCOLstart = $iCOLend
    $iCOLend = $tmp
    EndSelect
    For $i = $iROWstart To $iROWend
    $tmp = ''
    For $k = $iCOLstart To $iCOLend
    If $k < $iCOLend Then
    $tmp &= $ARRAY[$i][$k] & $DELIM
    Else
    $tmp &= $ARRAY[$i][$k]
    EndIf
    Next
    FileWriteLine($fh, $tmp)
    Next
    EndIf
    FileClose($fh)
    Return -1
    EndFunc ;==>_FileWriteFromArray2D

    [/autoit]

    Funktioniert bei mir einwandfrei, -1 heißt bei dieser Funkltion auch erfolgreich

  • Hallo,

    ich hab's

    [autoit]


    _FileWriteFromArray2D(@ScriptDir & "\Testneu.txt", $aTexte)

    [/autoit]

    jetzt wird geschrieben!

    Seltsam, oder?

    ;) Grüße Ilse

    Hoffentlich klappt das nun mit dem einlesen!