2D Array in txt Datei speichern

  • Versuche jetzt schon eine ganze weile mein 2d Array zu speichern und ständig stürzt mein Script ab.. kann mir jemand sagen was der Fehler ist?

    [autoit]


    #include <ie.au3>
    #include <array.au3>
    #include <string.au3>
    #include <file.au3>

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

    Global $arrProxy[1]
    Global $arrPort[1]

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

    $oIE = _IECreate("http://www.proxy-listen.de/Proxy/Proxyliste.html",0,0,1)
    for $j=1 to 3

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

    if $j = 1 Then
    $oSubmit = _IEGetObjByName ($oIE, "submit") ; beim ersten Durchlauf wird der "Anzeigen" Button gedrückt
    Else
    $oSubmit = _IEGetObjById ($oIE, "next_page") ; bei weiteren Durchläufen wird der "Nächste Seite" Button gedrückt
    EndIf
    _IEAction ($oSubmit, "click")
    _IELoadWait ($oIE)
    $sHTML = _IEBodyReadHTML ($oIE)
    $arrTempProxy = _StringBetween($sHTML, 'blank">', '</a>') ;quelltext lesen Proxy
    $arrTempPort = _StringBetween($sHTML,'&amp;port=','&amp') ;quelltext lesen Port

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

    For $i = 0 to UBound($arrTempProxy)-1 ;Proxy extrahieren
    if StringRegExp($arrTempProxy[$i],"\d+\.\d+\.\d+\.\d+",0) = 1 Then
    _ArrayAdd($arrProxy,$arrTempProxy[$i])
    EndIf
    Next

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

    For $k = 0 to UBound($arrTempPort)-1 ;Port extrahieren
    if StringRegExp($arrTempPort[$k],"\d+",0) = 1 Then
    _ArrayAdd($arrPort,$arrTempPort[$k])
    EndIf
    Next

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

    Next

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

    $iRows = UBound($arrProxy) ; verbindet Proxys und Prot in ein 2D Array
    If $iRows < UBound($arrProxy) Then $iRows = UBound($arrPort) - 1

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

    Dim $aOutput[$iRows][2]

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

    For $x = 0 To $iRows - 1
    If $x > UBound($arrProxy) - 1 Then ContinueLoop
    $aOutput[$x][0] = $arrProxy[$x]
    If $x > UBound($arrPort) - 1 Then ContinueLoop
    $aOutput[$x][1] = $arrPort[$x]
    Next
    _ArrayDisplay($aOutput)
    _FileWriteFromArray(@ScriptDir & "\proxyliste.txt",$aOutput,1,UBound($aOutput)-1,":");speichert Proxy:Port in txt

    [/autoit]

    Einmal editiert, zuletzt von ManniMensen (7. März 2012 um 21:46)

  • Zitat

    C:\Program Files (x86)\AutoIt3\Include\file.au3 (272) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
    $s_Temp &= $s_Delim & $a_Array[$x][$y]
    $s_Temp &= $s_Delim & ^ ERROR

    Es liegt definitiv an der Zeile:

    [autoit]

    _FileWriteFromArray(@ScriptDir & "\proxyliste.txt",$aOutput,1,UBound($aOutput)-1,":")

    [/autoit]


    Ich habe die hilfe durchsucht und es sieht alles richtig aus..

    Eindimensionale Arrays speichert er ohne Probleme..

  • Zitat


    _FileWriteFromArray($File, $a_Array [, $i_Base = 0 [, $i_UBound = 0 [, $s_Delim= "|"]]])
    $s_Delim [optional] - Delimiter character(s) for 2-dimension arrays. default="|"


    Das stand in meiner Hilfe deshalb bin ich von 2d arrays ausgegangen..

  • Also in meiner Hilfe steht das nicht so. Evtl. wurde das in der neuesten Autoit Version eingeführt und entsprechend in der Hilfe angepasst, aber du verwendest noch eine ältere Version?

  • bei mir läuft die neueste beta. ich werde eventuell mal neu installieren und testen

  • Da hat die Funktion meiner Meinung nach einen Fehler.

    Original

    Spoiler anzeigen
    [autoit]

    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

    [/autoit]


    Das Problem dürfte im Case 2 Block liegen. Die FOR-Schleife läuft bei einem 2D Array von 1 bis 2 ($iDims) und schon wird eine Spalte angesprochen, die es nicht gibt.

    Ungetestet aber so sollte es funktionieren

    Spoiler anzeigen
    [autoit]

    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] & $s_Delim & $a_Array[$x][1]
    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]