_fileWriteFromArray schreibt nur 3 Einträge

  • mahlzeit,

    in folgendem Script versuche ich ein komplettes (2dimensionales) Array in eine TXT datei zu schreiben und auf dem Desktop abzulegen. Allerdings werden nur die jeweils
    ersten 3 Einträge in die datei geschrieben. Der Befehl _arrayDisplay arbeitet aber korrekt und zeigt alle Einträge an. Hat jemand eine idee, warum in der Datei nur
    die jeweils ersten 3 Einträge landen?

    thx

    code

    Spoiler anzeigen
    [autoit]


    #include<file.au3>
    #include <Array.au3>
    global $array[2][6]
    $array[0][0] = "Hannes"
    $array[0][1] = "Holger"
    $array[0][2] = "Jon"
    $array[0][3] = "Maik"
    $array[0][4] = "mr.nobody"
    $array[0][5] = "stefan"
    $array[1][0] = "spielen"
    $array[1][1] = "schreiben"
    $array[1][2] = "gammeln"
    $array[1][3] = "schlafen"
    $array[1][4] = "ruhen"
    $array[1][5] = "rennen"
    _arrayDisplay($array)
    $answer = _FileWriteFromArray(@DesktopDir& "\dummy.txt" , $array,0,0)
    msgBox(0,$answer,@error)

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

    Exit

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

    ;-----------------entsprechender Code aus der File.au3--------------
    #cs
    Func _FileWriteFromArray($File, $a_Array, $i_Base = 0, $i_UBound = 0, $s_Delim = "|")
    ; Check if we have a valid array as input
    If Not IsArray($a_Array) Then Return SetError(2, 0, 0)
    Local $iDims = UBound($a_Array, 0)
    If $iDims > 2 Then Return SetError(4, 0, 0)

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

    ; determine last entry
    Local $last = UBound($a_Array) - 1
    If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
    If $i_Base < 0 Or $i_Base > $last Then $i_Base = 0

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

    ; Open output file for overwrite by default, or use input file handle if passed
    Local $hFile
    If IsString($File) Then
    $hFile = FileOpen($File, $FO_OVERWRITE)
    Else
    $hFile = $File
    EndIf
    If $hFile = -1 Then Return SetError(1, 0, 0)

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

    ; Write array data to file
    Local $ErrorSav = 0
    Switch $iDims
    Case 1
    For $x = $i_Base To $i_UBound
    If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
    $ErrorSav = 3
    ExitLoop
    EndIf
    Next
    Case 2
    Local $s_Temp
    For $x = $i_Base To $i_UBound
    $s_Temp = $a_Array[$x][0]
    For $y = 1 To $iDims
    $s_Temp &= $s_Delim & $a_Array[$x][$y]
    Next
    If FileWrite($hFile, $s_Temp & @CRLF) = 0 Then
    $ErrorSav = 3
    ExitLoop
    EndIf
    Next
    EndSwitch

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

    ; Close file only if specified by a string path
    If IsString($File) Then FileClose($hFile)

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

    ; Return results
    If $ErrorSav Then Return SetError($ErrorSav, 0, 0)
    Return 1
    EndFunc ;==>_FileWriteFromArray
    #ce

    [/autoit]

    SollErgebnis

    Spoiler anzeigen

    Hannes|Holger|Jon|Maik|mr.nobody|stefan
    spielen|schreiben|gammeln|schlafen|ruhen|rennen

    IstErgebnis

    Spoiler anzeigen

    Hannes|Holger|Jon
    spielen|schreiben|gammeln

    Für Rechtschreibfehler gibt es keinen Finderlohn!!

    Einmal editiert, zuletzt von WiDDoW (7. Juli 2012 um 19:00)

  • Irgendwie sieht es so aus als hätt sich da jemand verschrieben...
    So geht's:

    Spoiler anzeigen
    [autoit]

    #include <File.au3>
    #include <Array.au3>
    global $array[2][6]
    $array[0][0] = "Hannes"
    $array[0][1] = "Holger"
    $array[0][2] = "Jon"
    $array[0][3] = "Maik"
    $array[0][4] = "mr.nobody"
    $array[0][5] = "stefan"
    $array[1][0] = "spielen"
    $array[1][1] = "schreiben"
    $array[1][2] = "gammeln"
    $array[1][3] = "schlafen"
    $array[1][4] = "ruhen"
    $array[1][5] = "rennen"
    _arrayDisplay($array)
    $answer = _FileWriteFromArrayFixed(@DesktopDir& "\dummy.txt" , $array,0,0)

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

    Func _FileWriteFromArrayFixed($File, $a_Array, $i_Base = 0, $i_UBound = 0, $s_Delim = "|")
    ; Check if we have a valid array as input
    If Not IsArray($a_Array) Then Return SetError(2, 0, 0)
    Local $iDims = UBound($a_Array, 0)
    If $iDims > 2 Then Return SetError(4, 0, 0)

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

    ; determine last entry
    Local $last = UBound($a_Array) - 1
    If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
    If $i_Base < 0 Or $i_Base > $last Then $i_Base = 0

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

    ; Open output file for overwrite by default, or use input file handle if passed
    Local $hFile
    If IsString($File) Then
    $hFile = FileOpen($File, $FO_OVERWRITE)
    Else
    $hFile = $File
    EndIf
    If $hFile = -1 Then Return SetError(1, 0, 0)

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

    ; Write array data to file
    Local $ErrorSav = 0
    Switch $iDims
    Case 1
    For $x = $i_Base To $i_UBound
    If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
    $ErrorSav = 3
    ExitLoop
    EndIf
    Next
    Case 2
    Local $s_Temp
    For $x = $i_Base To $i_UBound
    $s_Temp = $a_Array[$x][0]
    For $y = 1 To UBound($a_Array, 2)-1 ; <---- $iDims ist hier immer 2, also wohl ein Programmierfehler...
    $s_Temp &= $s_Delim & $a_Array[$x][$y]
    Next
    If FileWrite($hFile, $s_Temp & @CRLF) = 0 Then
    $ErrorSav = 3
    ExitLoop
    EndIf
    Next
    EndSwitch

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

    ; Close file only if specified by a string path
    If IsString($File) Then FileClose($hFile)

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

    ; Return results
    If $ErrorSav Then Return SetError($ErrorSav, 0, 0)
    Return 1
    EndFunc ;==>_FileWriteFromArray

    [/autoit]
  • jep - jetzt läufts danke.
    (hatte mir schon gedacht das die Funktion vielleicht einen fehler hat und hatte sie deshalb gleich mit reingepostet)

    ist der fehler bekannt? oder sollte man da ggf nochmal im eng. forum posten damit das zukünftig gefixt wird?

    Für Rechtschreibfehler gibt es keinen Finderlohn!!