FOR Schleife so lange bis ARRAY leer ist

  • Hi Leute,

    wie schaffe ich es das ich eine FOR Schleife so lange ausführe bis ein ARRAY leer ist ?

    es ist bei mir so: ich mach mir ein ARRAY und befülle es:

    [autoit]

    Dim $A_FILEEXTS
    $A_FILEEXTS= _ArrayCreate("*.A", "*.J", "*.K", "*.B", "*.S", "*.U", "*.V")

    [/autoit]


    dann soll die FOR Schleife eine Dateiüberprüfung machen und zum Schluss wird der erste ARRAY Datensatz gelöscht.

    momentan fängt die FOR Schleife so an :

    [autoit]

    For $i = 0 To 7 Step 1
    .........DATENVERARBEITUNG......................
    _ArrayDelete($A_FILEEXTM,0)
    Next

    [/autoit]

    Danke für eure Hilfe

  • Deine Forschleife sollte eigtl nicht gehen weil du 8 Arrayelemente löschen willst aber nur 7 da sind. Zudem kannst du den 0. wert mit der anzahl der elemente füllen und dann von 1 bis $array[0] durchlaufen lassen

  • So ich hab jetzt mal das ARRAY und die FOR Schleife abgeändert

    ARRAY:

    [autoit]

    Dim $A_FILEEXTS[7][2]
    $A_FILEEXTS[0][0]="*.A"
    $A_FILEEXTS[1][0]="*.J"
    $A_FILEEXTS[2][0]="*.K"
    $A_FILEEXTS[3][0]="*.B"
    $A_FILEEXTS[4][0]="*.S"
    $A_FILEEXTS[5][0]="*.U"
    $A_FILEEXTS[6][0]="*.V"
    $A_FILEEXTS[0][1]="A" & $s_mandant & " File (Mitarbeiter Export)"
    $A_FILEEXTS[1][1]="J" & $s_mandant & " File (Journal Export)"
    $A_FILEEXTS[2][1]="K" & $s_mandant & " File (Kunden Export)"
    $A_FILEEXTS[3][1]="B" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[4][1]="S" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[5][1]="U" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[6][1]="V" & $s_mandant & " File (Buchungs Gesamt Preis Liste Export)"
    Dim $A_FILEEXTM [1][2]
    $A_FILEEXTM[0][0]="*.M"
    $A_FILEEXTM[0][1]="M" & $s_mandant & " File (MIS Export)"

    [/autoit]

    FOR Schleife :

    [autoit]

    For $i = 1 To UBound($A_FILEEXTS[$i][0]) Step 1

    [/autoit]

    es funzt aber trozdem nicht :(


    Kann mir jemand helfen ..... bin leider anfänger und kämpfe gegen windmühlen .....

  • Du deklarierst den Wert im array element 0 auch gar nicht da kannste den auch nicht abfragen -..-

  • am besten ich schick mal das ganze Script:

    Spoiler anzeigen
    [autoit]

    #comments-start
    CopyRight 2007 (c) Garnreiter
    (Schript vereinfacht und gekürzt 2007 (c) teh_hahn)
    Version 7.0.0.1
    #comments-end
    #NoTrayIcon
    #include <Date.au3>
    #include <File.au3>
    #include <Array.au3>

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

    Opt("MustDeclareVars", 1)
    Opt("RunErrorsFatal", 0)

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

    Func CheckFile($s_filename, $i_mode = 2)
    Local $h_file = -1
    $h_file = FileOpen($s_filename, $i_mode)
    If $h_file == -1 Then
    MsgBox(16, "Error", "Unable to open file.")
    Exit (1)
    EndIf
    Return ($h_file)
    EndFunc ;==>CheckFile

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

    Func FailMailExists($s_filename, $s_mandant)
    Local $h_file = -1
    $h_file = CheckFile($s_filename, 2)
    FileWrite($h_file, "To: [email='Helpdesk@aa.bbb'][/email]" & @CRLF)
    FileWrite($h_file, "Subject: " & @MDAY & "." & @MON & "." & @YEAR & " A C H T U N G !! Der Jack (Mandant: " & $s_mandant & ") hat Datenüberleitungs Probleme!" & @CRLF & @CRLF)
    FileWrite($h_file, "Diese Files sind auf dem CRS nicht vorhanden :" & @CRLF & @CRLF)

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

    Return ($h_file)
    EndFunc ;==>FailMailExists

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

    Local Const $S_CONFIGFILE = @ScriptDir & "\Export.ini"
    Local Const $S_EMPTYVAL = "Keine Pfad konfiguriert"
    Local Const $S_OKFILE = @ScriptDir & "\OK_MAIL.txt"
    Local Const $S_FAILFILE = @ScriptDir & "\Fail_MAIL.txt"
    Local Const $S_OKSMSFILE = @ScriptDir & "\OK_SMS.TXT"
    Local Const $S_FAILSMSFILE = @ScriptDir & "\Fail_SMS.TXT"
    ;~ Local Const $s_smsrecipient = ""
    Local $s_mandant = IniRead($S_CONFIGFILE, "MANDANT", "MAN", $S_EMPTYVAL)
    ;---ARRAY erstellen ---------------------------------------------------------------------------------;
    Dim $A_FILEEXTS[7][2]
    $A_FILEEXTS[0][0] = "*.A"
    $A_FILEEXTS[1][0] = "*.J"
    $A_FILEEXTS[2][0] = "*.K"
    $A_FILEEXTS[3][0] = "*.B"
    $A_FILEEXTS[4][0] = "*.S"
    $A_FILEEXTS[5][0] = "*.U"
    $A_FILEEXTS[6][0] = "*.V"
    $A_FILEEXTS[0][1] = "A" & $s_mandant & " File (Mitarbeiter Export)"
    $A_FILEEXTS[1][1] = "J" & $s_mandant & " File (Journal Export)"
    $A_FILEEXTS[2][1] = "K" & $s_mandant & " File (Kunden Export)"
    $A_FILEEXTS[3][1] = "B" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[4][1] = "S" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[5][1] = "U" & $s_mandant & " File (SAP Export)"
    $A_FILEEXTS[6][1] = "V" & $s_mandant & " File (Buchungs Gesamt Preis Liste Export)"
    Dim $A_FILEEXTM [1][2]
    $A_FILEEXTM[0][0] = "*.M"
    $A_FILEEXTM[0][1] = "M" & $s_mandant & " File (MIS Export)"
    ;---ARRAY erstellen Ende ----------------------------------------------------------------------------;

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

    Local $s_crspath = IniRead($S_CONFIGFILE, "PFADE", "CRS", $S_EMPTYVAL)
    Local $s_crsmpath = IniRead($S_CONFIGFILE, "PFADE", "CRSM", $S_EMPTYVAL)
    Local $s_crswpath = IniRead($S_CONFIGFILE, "PFADE", "CRSW", $S_EMPTYVAL)
    Local $s_rootpath = IniRead($S_CONFIGFILE, "PFADE", "root", $S_EMPTYVAL)
    Local $s_timeend = IniRead($s_rootpath & "\log\time.stamp", "TIME", "ende", "Time_Stamp_Not_Found")
    Local $s_mailsender = IniRead($S_CONFIGFILE, "MAIL", "FROM", "Jack@aa.bb")

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

    Local $s_mailrecipient = "Thomas.G@aa.bb"
    Local $s_mailrecipientNO = "Thomas.G@aa.bb"
    Local $s_smsrecipient = "00000000000@SMSGATEWAY.aa.bb"
    Local $s_smsrecipientNO = "000000000000@SMSGATEWAY.aa.bb"

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

    ;~ Local $s_mailrecipient= IniRead($S_CONFIGFILE, "MAIL", "TO", "Jack@aa.bb")
    ;~ Local $s_mailrecipientNO= IniRead($S_CONFIGFILE, "MAIL", "TON", "Jack@aa.bb")
    ;~ Local Const $s_smsrecipientNO = IniRead($S_CONFIGFILE, "MAIL", "TOSMS", "000000000000@SMSGATEWAY.aa.bb")
    ;~ Local Const $s_smsrecipient = "00000000000@SMSGATEWAY.aa.bb"
    Local $s_mailserver = IniRead($S_CONFIGFILE, "MAIL", "SRV", "172.30.241.40")
    Local $s_currentfile, $s_currentfilem, $s_filetime = "", $s_filetimem = ""
    Local $a_filetime, $a_filetimem, $h_file = -1

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

    ;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
    ;-----Datenverarbeitungsbereich-----------------------------------------------------------------------------------------------------------------------------------------------------------;
    ;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;

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

    ;~ For $i In $A_FILEEXTS
    For $i = 1 To UBound($A_FILEEXTS[0][0]) Step 1
    ;~ For $i = 0 To $A_FILEEXTS Step 1
    $s_currentfile = $s_crswpath & "\" & $A_FILEEXTS[$i][0] & $s_mandant
    If FileExists($s_currentfile) Then
    $a_filetime = FileGetTime($s_currentfile, 1, 0)
    If _DateTimeFormat(_DateAdd('d', -1, $a_filetime[0] & "/" & $a_filetime[1] & "/" & $a_filetime[2]), 2) == $s_timeend Then
    If Not FileExists($S_OKFILE) Then
    ;~ If Not FileExists($S_OKFILE) == 1 Then
    $h_file = CheckFile($S_OKFILE, 2)
    FileWriteLine($h_file, "To: [email='Helpdesk@verkehrsbuero.at'][/email]" & @CRLF)
    FileWriteLine($h_file, "Subject: " & @MDAY & "." & @MON & "." & @YEAR & " Der Jack (Mandant: " & $s_mandant & ") hat die Daten auf den CRS übergeleitet!" & @CRLF & @CRLF)
    FileWriteLine($h_file, "Die Files sind auf dem CRS vorhanden:" & @CRLF & @CRLF)
    Else
    $h_file = CheckFile($S_OKFILE, 1)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTS[$i][1] & " ist vorhanden" & @CRLF & @CRLF)

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

    FileClose($h_file)
    Else
    If FileExists($S_FAILFILE) == 1 Then
    $h_file = CheckFile($S_FAILFILE, 1)
    Else
    $h_file = FailMailExists($S_FAILFILE, $s_mandant)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTS[$i][1] & " ist mit falschen Datum vorhanden!" & @CRLF & @CRLF)
    FileWriteLine($h_file, "Bitte die Überleitung auf der CTWS04 Überprüfen" & @CRLF & @CRLF)
    FileClose($h_file)
    EndIf
    Else
    If FileExists($S_FAILFILE) == 1 Then
    $h_file = CheckFile($S_FAILFILE, 1)
    Else
    $h_file = FailMailExists($S_FAILFILE, $s_mandant)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTS[$i][1] & " ist nicht vorhanden" & @CRLF & @CRLF)
    FileClose($h_file)
    EndIf
    _ArrayDelete($A_FILEEXTS[0], 0)
    Next

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

    ;~ For $i In $A_FILEEXTM
    For $i = 1 To UBound($A_FILEEXTM[0][0]) Step 1
    ;~ For $i = 0 To $A_FILEEXTM Step 1
    $s_currentfilem = $s_crsmpath & "\" & $A_FILEEXTM[$i][0] & $s_mandant
    If FileExists($s_currentfilem) Then
    $a_filetimem = FileGetTime($s_currentfilem, 1, 0)
    If _DateTimeFormat(_DateAdd('d', -1, $a_filetimem[0] & "/" & $a_filetimem[1] & "/" & $a_filetimem[2]), 2) == $s_timeend Then
    If Not FileExists($S_OKFILE) Then
    ;~ If Not FileExists($S_OKFILE) == 1 Then
    $h_file = CheckFile($S_OKFILE, 2)
    FileWriteLine($h_file, "To: [email='Helpdesk@verkehrsbuero.at'][/email]" & @CRLF)
    FileWriteLine($h_file, "Subject: " & @MDAY & "." & @MON & "." & @YEAR & " Der Jack (Mandant: " & $s_mandant & ") hat die Daten auf den CRS übergeleitet!" & @CRLF & @CRLF)
    FileWriteLine($h_file, "Die Files sind auf dem CRS vorhanden:" & @CRLF & @CRLF)
    Else
    $h_file = CheckFile($S_OKFILE, 1)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTM[$i][1] & " ist vorhanden" & @CRLF & @CRLF)

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

    FileClose($h_file)
    Else
    If FileExists($S_FAILFILE) == 1 Then
    $h_file = CheckFile($S_FAILFILE, 1)
    Else
    $h_file = FailMailExists($S_FAILFILE, $s_mandant)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTM[$i][0] & " ist mit falschen Datum vorhanden!" & @CRLF & @CRLF)
    FileWriteLine($h_file, "Bitte die Überleitung auf der CTWS04 Überprüfen" & @CRLF & @CRLF)
    FileClose($h_file)
    EndIf
    Else
    If FileExists($S_FAILFILE) == 1 Then
    $h_file = CheckFile($S_FAILFILE, 1)
    Else
    $h_file = FailMailExists($S_FAILFILE, $s_mandant)
    EndIf
    FileWriteLine($h_file, "Das " & $A_FILEEXTM[$i][0] & " ist nicht vorhanden" & @CRLF & @CRLF)
    FileClose($h_file)
    EndIf
    _ArrayDelete($A_FILEEXTM[0], 0)
    Next

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

    ;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
    ;-----MAIL & SMS Sendebereich-------------------------------------------------------------------------------------------------------------------------------------------------------------;
    ;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;

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

    If FileExists($S_FAILFILE) == 1 Then
    $h_file = CheckFile($S_FAILSMSFILE, 2)
    FileWrite($h_file, " Der Jack-Mandant: " & $s_mandant & " hat Datenueberleitungsprobleme! Bitte um Kontrolle!")
    FileClose($h_file)
    RunWait(@ScriptDir & "\VMAILER.EXE " & $S_FAILSMSFILE & " " & $s_mailserver & " " & $s_smsrecipientNO & " " & $s_mailsender)
    MsgBox(0, "Fail SMS", " Der Jack-Mandant: " & $s_mandant & " hat Datenueberleitungsprobleme! Bitte um Kontrolle!")
    FileDelete($S_FAILSMSFILE)
    Sleep(3000)
    RunWait(@ScriptDir & "\VMAILER.EXE " & $S_FAILFILE & " " & $s_mailserver & " " & $s_mailrecipientNO & " " & $s_mailsender)
    MsgBox(0, "Fail Mail", " Der Jack-Mandant: " & $s_mandant & " hat Datenueberleitungsprobleme! Bitte um Kontrolle!")
    FileDelete($S_FAILFILE)
    Else
    $h_file = CheckFile($S_OKSMSFILE, 2)
    FileWrite($h_file, " Der Jack-Mandant: " & $s_mandant & " hat alle Daten uebergeleitet")
    FileClose($h_file)
    RunWait(@ScriptDir & "\VMAILER.EXE " & $S_OKSMSFILE & " " & $s_mailserver & " " & $s_smsrecipient & " " & $s_mailsender)
    MsgBox(0, "OK SMS", " Der Jack-Mandant: " & $s_mandant & " hat alle Daten uebergeleitet")
    FileDelete($S_OKSMSFILE)
    Sleep(3000)
    RunWait(@ScriptDir & "\VMAILER.EXE " & $S_OKFILE & " " & $s_mailserver & " " & $s_mailrecipient & " " & $s_mailsender)
    MsgBox(0, "OK Mail", " Der Jack-Mandant: " & $s_mandant & " hat alle Daten uebergeleitet")
    FileDelete($S_OKFILE)
    EndIf

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

    Run(@ScriptDir & '\Speicher_Warnung.exe', @ScriptDir)

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

    Exit

    [/autoit]
    • Offizieller Beitrag

    So kann das nicht funktionieren, schau dir mal die Hilfe zu UBound an (incl. Bsp.)!

    Zeile 91 muss lauten:

    [autoit]

    For $i = 1 To UBound($A_FILEEXTS)-1 Step 1

    [/autoit]


    und Zeile 132:

    [autoit]

    For $i = 1 To UBound($A_FILEEXTM)-1 Step 1

    [/autoit]