Array variable has incorrect number of subscripts...

  • Hi. Habe ein "kleines" Problem mit dem folgenden Skript. Wurde mal geschrieben um Datein aus einem Ordner zu verschlüsseln, per Mail zu senden, wieder zu entschlüsseln und zu drucken. Jetzt muss ich eigentlich nur den Mailserver ändern, bekomme aber beim kompilieren immer folgende Fehlermeldung:

    Zitat

    Line 0 (File "C:\scanner\get-sendmail-de.v2.exe")

    $PDFfiles[0][0]+=1
    ^ERROR

    Error: Array variable hast incorrect number of subscripts or subscript dimension range exceeded

    Hier der Programmcode:

    Spoiler anzeigen
    [autoit]

    $g_szVersion = 'PDF Mailer'
    If WinExists($g_szVersion) Then Exit; It's already running
    AutoItWinSetTitle($g_szVersion)
    opt("RunErrorsFatal", 0)
    opt("TrayAutoPause", 0)
    Global $Sender, $Recipient, $MailUser, $MailPass
    Global $Enable_Encryption = True
    Global $Drive
    If $CmdLine[0] > 0 Then
    If StringInStr($CmdLine[1], "deutschland") And StringInStr($CmdLine[1], "polen") Then Exit ;;can't run both at the same time!
    If StringInStr($CmdLine[1], "deutschland") Then
    $Sender = '1@sender.com'
    $Recipient = '2@sender.com'
    $MailUser = 'x'
    $MailPass = 'x'
    $Drive = 'C:'
    ElseIf StringInStr($CmdLine[1], "polen") Then
    $Sender = '2@sender.com'
    $Recipient = '1@sender.com'
    $MailUser = 'x'
    $MailPass = 'x'
    $Drive = 'D:'
    ElseIf StringInStr($CmdLine[1], "/?") Then
    MsgBox(32, $g_szVersion, "This program has two arguments, which must be in order." & @CRLF & _
    "The first argument is country, which can either be deutschland or polen." & @CRLF & @CRLF & _
    "The second argument is optional, controlling encryption." & @CRLF & _
    "Passing noencrypt as the second argument will disable encryption")
    Exit
    Else
    Exit
    EndIf
    If $CmdLine[0] > 1 Then
    If StringInStr($CmdLine[2], "noencrypt") Then $Enable_Encryption = False
    EndIf
    Else
    Exit
    EndIf
    #region Configuration Settings
    Global Const $Blowfish_Password = 'passwort'
    Global Const $POP3Server = 'pop3.sender.com'
    Global Const $SMTPServer = 'smtp.sender.com'
    ;SendMail Configuration
    Global Const $SendMail = $Drive & '\scanner\sendmail'
    Global Const $PDF_Dir = $Drive & '\scanner\sendmail\Emails'
    ;GetMail Configuration
    Global Const $GetMail = $Drive & '\scanner\getmail'
    Global Const $source = $Drive & '\scanner\getmail\Emails' ; Location of encrypted PDF files
    Global Const $dest = $Drive & '\scanner\getmail\Emails\Archives' ; Location of decrypted PDF files
    Global Const $GSPrintDir = $Drive & '\scanner\Print\Ghostgum\gsview' ;Path to PDF Printer Program
    #endregion Configuration Settings
    #region Do Not Edit!!!!!
    #region GetMail Functions
    Func GetMail()
    Local $Files[1][1]
    If Not FileExists($source) Then DirCreate($source)
    If Not FileExists($dest) Then DirCreate($dest)
    FileChangeDir($GetMail)
    RunWait('getmail.exe -u ' & $MailUser & ' -pw ' & $MailPass & ' -s ' & $POP3Server & ' -xtract -delete', '', @SW_HIDE)
    ;FileDelete('*.txt')
    FileDelete('*.out')
    FileMove('*.pdf', $source & '\*.pdf', 1)
    FileMove('MSG*.txt', $source & '\MSG*.pdf', 1)
    Sleep(1000)
    Local $file = FileFindFirstFile($source & '\*.pdf')
    If $file = -1 Then Return 0
    While 1
    Local $pdffile = FileFindNextFile($file)
    If @error Then ExitLoop
    ReDim $Files[UBound($Files) + 1][2]
    $Files[UBound($Files) - 1][0] = $pdffile
    WEnd
    FileClose($file)
    Local $file = FileFindFirstFile($source & '\MSG*.txt')
    If $file = -1 Then Return 0
    While 1
    Local $txtfile = FileFindNextFile($file)
    If @error Then ExitLoop
    Local $fHandle, $fLine, $fMD5, $fName
    $fHandle = FileOpen($txtfile, 0)
    While 1
    $fLine = FileReadLine($fHandle)
    If @error = -1 Then ExitLoop
    If StringInStr($fLine, "Subject: ") Then
    $fMD5 = StringRight($fLine, StringLen($fLine) - 9)
    EndIf
    If StringInStr($fLine, "Content-Type: application/pdf;") Then
    $fLine = FileReadLine($fHandle)
    $fName = StringRight($fLine, StringLen($fLine) - 7)
    $fName = StringLeft($fLine, StringLen($fName) - 1)
    ExitLoop
    EndIf
    WEnd
    FileClose($fHandle)
    FileDelete($txtfile)
    For $iCurrentPos = 0 To UBound($Files) - 1
    If ($Files[$iCurrentPos][0] = $fName) Then $Files[$iCurrentPos][1] = $fMD5
    Next
    WEnd
    FileClose($file)
    For $x = 0 To UBound($Files) - 1
    If $Enable_Encryption Then
    RunWait('bfish.exe /I:"' & $source & '\' & $Files[$x][0] & '" /O:"' & $dest & '\' & $Files[$x][0] & '" /P:"' & $Blowfish_Password & '" /D /Q', "", @SW_HIDE)
    If FileExists($dest & '\' & $Files[$x][0]) Then
    ;File successfully decrypted, print it!
    ;If (FileMD5($dest & '\' $Files[$x][0]) = $Files[$x][1]) Then
    Local $WorkingDir = @WorkingDir
    FileChangeDir($GSPrintDir)
    RunWait('gsprint.exe "' & $dest & '\' & $Files[$x][0] & '"', $GSPrintDir, @SW_HIDE)
    FileChangeDir($WorkingDir)
    ;Else
    ;Send Error Log Entry
    ;EndIf
    EndIf
    Else
    FileMove($source & '\' & $Files[$x][0], $dest & '\')
    ;If (FileMD5($dest & '\' & $Files[$x][0]) = $Files[$x][1]) Then
    Local $WorkingDir = @WorkingDir
    FileChangeDir($GSPrintDir)
    RunWait('gsprint.exe "' & $dest & '\' & $Files[$x][0] & '"', $GSPrintDir, @SW_HIDE)
    FileChangeDir($WorkingDir)
    ;Else
    ;Send Error Log Entry
    ;EndIf
    EndIf
    FileDelete($source & '\' & $Files[$x][0]) ;delete the encrypted version
    Next
    Return 1
    EndFunc ;==>GetMail
    #endregion
    #region SendMail Functions
    Func SendMail()
    If Not FileExists($PDF_Dir) Then DirCreate($PDF_Dir)
    If Not FileExists($PDF_Dir & '\Encrypted\') Then DirCreate($PDF_Dir & '\Encrypted\')
    If Not FileExists($PDF_Dir & '\Archives\') Then DirCreate($PDF_Dir & '\Archives\')
    If Not FileExists($PDF_Dir & '\*.pdf') Then Return 0
    Local $PDFfiles[1][2]
    FileChangeDir($SendMail)
    Local $PDFHandle = FileFindFirstFile($PDF_Dir & '\*.pdf')
    While 1
    Local $file = FileFindNextFile($PDFHandle)
    If $file <> '' Then
    ReDim $PDFfiles[ (UBound($PDFfiles) + 1) ]
    $PDFfiles[0][0] += 1
    $PDFfiles[ (UBound($PDFfiles) - 1) ][0] = $file
    ;$PDFfiles[ (UBound($PDFfiles) - 1) ][1] = FileMD5($file)
    $PDFfiles[(UBound($PDFfiles) - 1 ][1] = ''
    Else
    ExitLoop
    EndIf
    WEnd
    FileClose($PDFHandle)
    For $x = 1 To $PDFfiles[0][0]
    If $Enable_Encryption = True Then
    RunWait('bfish.exe /I:"' & $PDF_Dir & '\' & $PDFfiles[$x][0] & '" /O:"' & $PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0] & '" /P:"' & $Blowfish_Password & '" /E /Q', "", @SW_HIDE)
    FileSend($PDFfiles[$x][0], $PDFfiles[$x][1], $PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0])
    Else
    FileSend($PDFfiles[$x][0], $PDFfiles[$x][1], $PDF_Dir & '\' & $PDFfiles[$x][0])
    EndIf
    FileMove($PDF_Dir & '\' & $PDFfiles[$x][0], $PDF_Dir & '\Archives\' & $PDFfiles[$x][0])
    FileDelete($PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0])
    Next
    Return 1
    EndFunc ;==>SendMail
    Func FileSend($FileName, $MD5Val, $Attachment)
    Local $objMessage = ObjCreate('CDO.Message')
    With $objMessage
    .Subject = $MD5Val
    .Sender = $Sender
    .From = $Sender
    .To = $Recipient
    .TextBody = ''
    .AddAttachment ($Attachment)
    EndWith
    With $objMessage.Configuration.Fields
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $MailUser
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $MailPass
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Update
    EndWith
    $objMessage.Send
    Return 1
    EndFunc ;==>FileSend
    #endregion
    Func ReduceMemoryUsage()
    Local $ai_GetCurrentProcessId = DllCall('kernel32.dll', 'int', 'GetCurrentProcessId')
    Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ai_GetCurrentProcessId[0])
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Return $ai_Return[0]
    EndFunc ;==>_ReduceMemoryUsage
    #endregion Do Not Edit
    ReduceMemoryUsage()
    While 1
    If ((@WDAY > 1) AND (@WDAY < 6)) Then
    If (@Hour >= 7) AND ((@HOUR & @MIN) <= 1630) Then
    GetMail()
    Sleep(1000 * 15) ;;Wait for 15 seconds
    SendMail()
    ReduceMemoryUsage()
    Sleep(1000 * 60 * 4.75) ;;Wait for 5 minutes
    EndIf
    Else
    Sleep(1000 * 60 * 60) ;Sleep for 1 hour if not
    EndIf
    WEnd

    [/autoit]

    Steigt da Jemand durch und kann mir sagen was falsch ist?

    Einmal editiert, zuletzt von Xenobiologist (19. März 2008 um 12:44)

  • Danke für deine Antwort Xenobiologist, nur wie spreche ich das Redim denn mit 1D an? Habe das Skript nicht selbst geschrieben und kenne mich auch mit Autoit nicht so furchtbar gut aus. Nur der der das Skript geschrieben hat ist leider nicht mehr erreichbar. Wäre nett wenn du mir da helfen könntest.

  • Also meinst du so?


    Spoiler anzeigen
    [autoit]

    $g_szVersion = 'PDF Mailer'
    If WinExists($g_szVersion) Then Exit; It's already running
    AutoItWinSetTitle($g_szVersion)
    opt("RunErrorsFatal", 0)
    opt("TrayAutoPause", 0)
    Global $Sender, $Recipient, $MailUser, $MailPass
    Global $Enable_Encryption = True
    Global $Drive
    If $CmdLine[0] > 0 Then
    If StringInStr($CmdLine[1], "deutschland") And StringInStr($CmdLine[1], "polen") Then Exit ;;can't run both at the same time!
    If StringInStr($CmdLine[1], "deutschland") Then
    $Sender = '1@sender.com'
    $Recipient = '2@sender.com'
    $MailUser = 'x'
    $MailPass = 'x'
    $Drive = 'C:'
    ElseIf StringInStr($CmdLine[1], "polen") Then
    $Sender = '2@sender.com'
    $Recipient = '1@sender.com'
    $MailUser = 'x'
    $MailPass = 'x'
    $Drive = 'D:'
    ElseIf StringInStr($CmdLine[1], "/?") Then
    MsgBox(32, $g_szVersion, "This program has two arguments, which must be in order." & @CRLF & _
    "The first argument is country, which can either be deutschland or polen." & @CRLF & @CRLF & _
    "The second argument is optional, controlling encryption." & @CRLF & _
    "Passing noencrypt as the second argument will disable encryption")
    Exit
    Else
    Exit
    EndIf
    If $CmdLine[0] > 1 Then
    If StringInStr($CmdLine[2], "noencrypt") Then $Enable_Encryption = False
    EndIf
    Else
    Exit
    EndIf
    #region Configuration Settings
    Global Const $Blowfish_Password = 'passwort'
    Global Const $POP3Server = 'pop3.sender.com'
    Global Const $SMTPServer = 'smtp.sender.com'
    ;SendMail Configuration
    Global Const $SendMail = $Drive & '\scanner\sendmail'
    Global Const $PDF_Dir = $Drive & '\scanner\sendmail\Emails'
    ;GetMail Configuration
    Global Const $GetMail = $Drive & '\scanner\getmail'
    Global Const $source = $Drive & '\scanner\getmail\Emails' ; Location of encrypted PDF files
    Global Const $dest = $Drive & '\scanner\getmail\Emails\Archives' ; Location of decrypted PDF files
    Global Const $GSPrintDir = $Drive & '\scanner\Print\Ghostgum\gsview' ;Path to PDF Printer Program
    #endregion Configuration Settings
    #region Do Not Edit!!!!!
    #region GetMail Functions
    Func GetMail()
    Local $Files[1][1]
    If Not FileExists($source) Then DirCreate($source)
    If Not FileExists($dest) Then DirCreate($dest)
    FileChangeDir($GetMail)
    RunWait('getmail.exe -u ' & $MailUser & ' -pw ' & $MailPass & ' -s ' & $POP3Server & ' -xtract -delete', '', @SW_HIDE)
    ;FileDelete('*.txt')
    FileDelete('*.out')
    FileMove('*.pdf', $source & '\*.pdf', 1)
    FileMove('MSG*.txt', $source & '\MSG*.pdf', 1)
    Sleep(1000)
    Local $file = FileFindFirstFile($source & '\*.pdf')
    If $file = -1 Then Return 0
    While 1
    Local $pdffile = FileFindNextFile($file)
    If @error Then ExitLoop
    ReDim $Files[UBound($Files) + 1][2]
    $Files[UBound($Files) - 1][0] = $pdffile
    WEnd
    FileClose($file)
    Local $file = FileFindFirstFile($source & '\MSG*.txt')
    If $file = -1 Then Return 0
    While 1
    Local $txtfile = FileFindNextFile($file)
    If @error Then ExitLoop
    Local $fHandle, $fLine, $fMD5, $fName
    $fHandle = FileOpen($txtfile, 0)
    While 1
    $fLine = FileReadLine($fHandle)
    If @error = -1 Then ExitLoop
    If StringInStr($fLine, "Subject: ") Then
    $fMD5 = StringRight($fLine, StringLen($fLine) - 9)
    EndIf
    If StringInStr($fLine, "Content-Type: application/pdf;") Then
    $fLine = FileReadLine($fHandle)
    $fName = StringRight($fLine, StringLen($fLine) - 7)
    $fName = StringLeft($fLine, StringLen($fName) - 1)
    ExitLoop
    EndIf
    WEnd
    FileClose($fHandle)
    FileDelete($txtfile)
    For $iCurrentPos = 0 To UBound($Files) - 1
    If ($Files[$iCurrentPos][0] = $fName) Then $Files[$iCurrentPos][1] = $fMD5
    Next
    WEnd
    FileClose($file)
    For $x = 0 To UBound($Files) - 1
    If $Enable_Encryption Then
    RunWait('bfish.exe /I:"' & $source & '\' & $Files[$x][0] & '" /O:"' & $dest & '\' & $Files[$x][0] & '" /P:"' & $Blowfish_Password & '" /D /Q', "", @SW_HIDE)
    If FileExists($dest & '\' & $Files[$x][0]) Then
    ;File successfully decrypted, print it!
    ;If (FileMD5($dest & '\' $Files[$x][0]) = $Files[$x][1]) Then
    Local $WorkingDir = @WorkingDir
    FileChangeDir($GSPrintDir)
    RunWait('gsprint.exe "' & $dest & '\' & $Files[$x][0] & '"', $GSPrintDir, @SW_HIDE)
    FileChangeDir($WorkingDir)
    ;Else
    ;Send Error Log Entry
    ;EndIf
    EndIf
    Else
    FileMove($source & '\' & $Files[$x][0], $dest & '\')
    ;If (FileMD5($dest & '\' & $Files[$x][0]) = $Files[$x][1]) Then
    Local $WorkingDir = @WorkingDir
    FileChangeDir($GSPrintDir)
    RunWait('gsprint.exe "' & $dest & '\' & $Files[$x][0] & '"', $GSPrintDir, @SW_HIDE)
    FileChangeDir($WorkingDir)
    ;Else
    ;Send Error Log Entry
    ;EndIf
    EndIf
    FileDelete($source & '\' & $Files[$x][0]) ;delete the encrypted version
    Next
    Return 1
    EndFunc ;==>GetMail
    #endregion
    #region SendMail Functions
    Func SendMail()
    If Not FileExists($PDF_Dir) Then DirCreate($PDF_Dir)
    If Not FileExists($PDF_Dir & '\Encrypted\') Then DirCreate($PDF_Dir & '\Encrypted\')
    If Not FileExists($PDF_Dir & '\Archives\') Then DirCreate($PDF_Dir & '\Archives\')
    If Not FileExists($PDF_Dir & '\*.pdf') Then Return 0
    Local $PDFfiles[1][2]
    FileChangeDir($SendMail)
    Local $PDFHandle = FileFindFirstFile($PDF_Dir & '\*.pdf')
    While 1
    Local $file = FileFindNextFile($PDFHandle)
    If $file <> '' Then
    ReDim $PDFfiles[ (UBound($PDFfiles) + 1) ][2]
    $PDFfiles[0][0] += 1
    $PDFfiles[ (UBound($PDFfiles) - 1) ][0] = $file
    ;$PDFfiles[ (UBound($PDFfiles) - 1) ][1] = FileMD5($file)
    $PDFfiles[(UBound($PDFfiles) - 1 ][1] = ''
    Else
    ExitLoop
    EndIf
    WEnd
    FileClose($PDFHandle)
    For $x = 1 To $PDFfiles[0][0]
    If $Enable_Encryption = True Then
    RunWait('bfish.exe /I:"' & $PDF_Dir & '\' & $PDFfiles[$x][0] & '" /O:"' & $PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0] & '" /P:"' & $Blowfish_Password & '" /E /Q', "", @SW_HIDE)
    FileSend($PDFfiles[$x][0], $PDFfiles[$x][1], $PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0])
    Else
    FileSend($PDFfiles[$x][0], $PDFfiles[$x][1], $PDF_Dir & '\' & $PDFfiles[$x][0])
    EndIf
    FileMove($PDF_Dir & '\' & $PDFfiles[$x][0], $PDF_Dir & '\Archives\' & $PDFfiles[$x][0])
    FileDelete($PDF_Dir & '\Encrypted\' & $PDFfiles[$x][0])
    Next
    Return 1
    EndFunc ;==>SendMail
    Func FileSend($FileName, $MD5Val, $Attachment)
    Local $objMessage = ObjCreate('CDO.Message')
    With $objMessage
    .Subject = $MD5Val
    .Sender = $Sender
    .From = $Sender
    .To = $Recipient
    .TextBody = ''
    .AddAttachment ($Attachment)
    EndWith
    With $objMessage.Configuration.Fields
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $MailUser
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $MailPass
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Update
    EndWith
    $objMessage.Send
    Return 1
    EndFunc ;==>FileSend
    #endregion
    Func ReduceMemoryUsage()
    Local $ai_GetCurrentProcessId = DllCall('kernel32.dll', 'int', 'GetCurrentProcessId')
    Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ai_GetCurrentProcessId[0])
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Return $ai_Return[0]
    EndFunc ;==>_ReduceMemoryUsage
    #endregion Do Not Edit
    ReduceMemoryUsage()
    While 1
    If ((@WDAY > 1) AND (@WDAY < 6)) Then
    If (@Hour >= 7) AND ((@HOUR & @MIN) <= 1630) Then
    GetMail()
    Sleep(1000 * 15) ;;Wait for 15 seconds
    SendMail()
    ReduceMemoryUsage()
    Sleep(1000 * 60 * 4.75) ;;Wait for 5 minutes
    EndIf
    Else
    Sleep(1000 * 60 * 60) ;Sleep for 1 hour if not
    EndIf
    WEnd

    [/autoit]

    Nur Zeile 142 ändern? Dann kommt noch der selbe Fehler.

    Edit Mega: Spoiler und Autoit Tags

    Einmal editiert, zuletzt von Xenobiologist (27. März 2008 um 15:08)

  • Das wars leider nicht, jetzt passiert einfach garnichts. Allerdings startet das Programm immerhin schonmal ohne Fehlermeldung ;)

    Ich habe noch eine "alte" Version ausgegraben, die funktioniert. Nur leider sind da 2 Dinge nicht enthalten (nur von MO-Fr ausführen + die Laufwerksbuchstaben nach dem Argument wählen).

    Spoiler anzeigen

    Habe schon versucht wie beim ersten Skript einfach "If ((@WDAY > 1) AND (@WDAY < 6)) Then" einzufügen, nur kommt dann leider wieder eine Fehlermeldung.
    Gibts eigentlich mittlerweile ein "sichereres" Tool welches sich per Autoit ansteuern lässt als diese bfish.exe? undefinedundefinedundefinedundefined