_Array2DInsert Problem

  • Hey,

    hab mir von Bugfix das UDF _Array2DInsert geladen. Erstmal dicken Lob dafür! Aber nun zum Problem:

    ; Parameter $avArray Given Array
    ; $iElement 0-based Array Index, to insert new Element
    ; optional $sValue Value of new Element, parts must be seperate with '|'


    Der erste Para ist klar. Das ist das Array, wo man etwas einfügen möchte. So der zweite. Das ist die Zeile, wo der Eintrag gemacht werden soll. Kann das Allerdings sein, dass man nur in das erste Feld n Eintrag machen kann und nicht zB. in Zeile 2 Feld 4?

    Dann noch zum Value. Er zeigt bei mir nur die 0 an. Wenn ich z.B. "Tabelle" tippe, kommt nur n Fehler. Kann mir jemand helfen?

  • Kleines Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

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

    Dim $ar2D[5][2]

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

    $ar2D[0][0] = 'Zeile1/Spalte1'
    $ar2D[0][1] = 'Zeile1/Spalte2'

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

    $ar2D[1][0] = 'Zeile2/Spalte1'
    $ar2D[1][1] = 'Zeile2/Spalte2'

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

    $ar2D[2][0] = 'Zeile3/Spalte1'
    $ar2D[2][1] = 'Zeile3/Spalte2'

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

    $ar2D[3][0] = 'Zeile4/Spalte1'
    $ar2D[3][1] = 'Zeile4/Spalte2'

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

    $ar2D[4][0] = 'Zeile5/Spalte1'
    $ar2D[4][1] = 'Zeile5/Spalte2'

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

    _ArrayDisplay($ar2D)

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

    _Array2DInsert($ar2D, 3, "hallo welt|alles klar?")

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

    _ArrayDisplay($ar2D)

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

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;
    ; Function _Array2DInsert(ByRef $avArray, $iElement [, $sValue=''])
    ;
    ; Description Insert an Array element on a given position
    ; Works with any occurences in 2nd Dimension
    ; Works also with 1D-Array
    ;
    ; Parameter $avArray Given Array
    ; $iElement 0-based Array Index, to insert new Element
    ; optional $sValue Value of new Element, parts must be seperate with '|'
    ;
    ; Return Succes the given Array with new Element
    ; Failure 0 and set @error
    ; @error = 1 given array is not array
    ; @error = 2 given parts of Element too less/much
    ; @error = 3 $iElement larger then Ubound
    ;
    ; Author BugFix ([email='bugfix@autoit.de'][/email])
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Func _Array2DInsert(ByRef $avArray, $iElement, $sValue = '')
    If (Not IsArray($avArray)) Then
    SetError(1)
    Return 0
    EndIf
    Local $UBound2nd = UBound($avArray, 2)
    If @error = 2 Then
    Local $arTMP[UBound($avArray) + 1]
    If $iElement > UBound($avArray) Then
    SetError(3)
    Return 0
    EndIf
    For $i = 0 To UBound($arTMP) - 1
    If $i < $iElement Then
    $arTMP[$i] = $avArray[$i]
    ElseIf $i = $iElement Then
    If $i < UBound($avArray) Then
    $arTMP[$i] = $sValue
    $arTMP[$i + 1] = $avArray[$i]
    Else
    $arTMP[$i] = $sValue
    EndIf
    ElseIf ($i > $iElement) And ($i < UBound($avArray)) Then
    $arTMP[$i + 1] = $avArray[$i]
    EndIf
    Next
    Else
    Local $arTMP[UBound($avArray) + 1][$UBound2nd], $arValue
    If $sValue = '' Then
    For $i = 0 To $UBound2nd - 2
    $sValue &= '|'
    Next
    EndIf
    $arValue = StringSplit($sValue, '|')
    If $arValue[0] <> $UBound2nd Then
    SetError(2)
    Return 0
    EndIf
    If $iElement > UBound($avArray) Then
    SetError(3)
    Return 0
    EndIf
    For $i = 0 To UBound($arTMP) - 1
    If $i < $iElement Then
    For $k = 0 To $UBound2nd - 1
    $arTMP[$i][$k] = $avArray[$i][$k]
    Next
    ElseIf $i = $iElement Then
    If $i < UBound($avArray) Then
    For $k = 0 To $UBound2nd - 1
    $arTMP[$i][$k] = $arValue[$k + 1]
    $arTMP[$i + 1][$k] = $avArray[$i][$k]
    Next
    Else
    For $k = 0 To $UBound2nd - 1
    $arTMP[$i][$k] = $arValue[$k + 1]
    Next
    EndIf
    ElseIf ($i > $iElement) And ($i < UBound($avArray)) Then
    For $k = 0 To $UBound2nd - 1
    $arTMP[$i + 1][$k] = $avArray[$i][$k]
    Next
    EndIf
    Next
    EndIf
    $avArray = $arTMP
    EndFunc ;==>_Array2DInsert

    [/autoit]