Jump to content

Problem using _ArrayAdd


Recommended Posts

Hi,

I've written a script which reads a log file, identifies particular errors and then extracts the message IDs (it's a mail archiving server) and writes these to an SQL script file.

In order to do this I need to move the data between 3 different arrays, but I seem to be having an issue creating the second one in the chain $aAllMsgIDs, the scrip compiles OK but I get "Error: Subscript used with non-Array variable" when I run it:

Please can someone take a look at the code below and see if they can spot the error? I'm pretty sure its something to do with how I've used _ArrayAdd but I can't see what.

Dim $aEASIndexerLog, $aAllMsgIDs, $aUniqueMsgIDs, $LogEntry, $MsgID, $file1, $LastEntry, $ErrorMsg, $NewLastEntry

#Include <Array.au3>
#Include <File.au3>
#include <String.au3>

; Read contents of EASIndexer.log into an array
If Not _FileReadToArray('d:\easlog\EASIndexer.log', $aEASIndexerLog) Then
    ; If failed to open PSTList write an error and exit
    WriteToErrorLog('Unable to open EASIndexer.log')
    Exit
EndIf

; Create Script file to write too (any existing file will be deleted)
$file1 = FileOpen('d:\BadMsgIDs\BadMsgIDs.sql', 10)
; Write 1st line of SQL code
FileWriteLine($file1, "update ft_notify set typefld ='Z' where msgid in (")

;_ArrayDisplay($aEASIndexerLog)

;do for each line in the array
For $x = 1 to $aEASIndexerLog[0] Step 1
    ; Load the log entry from the array
    $LogEntry = StringStripWS($aEASIndexerLog[$x],2)
    If StringInStr($LogEntry,'openMsg: Error working with MsgID=') <> 0 Then
        $MsgID=StringLeft(StringRight($LogEntry,129),8)
        _ArrayAdd($aAllMsgIDs, $MsgID)
    Else
        ContinueLoop
    EndIf
Next

_ArrayDisplay($aAllMsgIDs)

$aUniqueMsgIDs = _ArrayUnique($aAllMsgIDs)

_ArrayDisplay($aUniqueMsgIDs)

For $x = 1 to $aUniqueMsgIDs[0] Step 1
    FileWriteLine($file1, $aUniqueMsgIDs[$x] & ',')
Next

FileWriteLine($file1, $MsgID & ')')

FileClose($file1)
Exit

Many thanks in adavance,

Phill.

Link to comment
Share on other sites

  • Moderators

You never declared $aAllMsgIDs as an array.

Dim $aEASIndexerLog, $aAllMsgIDs[], $aUniqueMsgIDs, $LogEntry, $MsgID, $file1, $LastEntry, $ErrorMsg, $NewLastEntry

 

Edit:

BTW, what version of autoit are you using?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi,

Many thanks for your reply.

Tried the fix, got a sytax error when compiling, checked the version, I was on 3.3.8.1 so updated to 3.3.12.0, recompiled with no errors, but I now get a run error "Line 5....Error: Variable subscript badly formatted" not sure what's causing this now.

Dim $aEASIndexerLog[], $aAllMsgIDs[], $aUniqueMsgIDs[], $LogEntry, $MsgID, $file1, $LastEntry, $ErrorMsg, $NewLastEntry

#Include <Array.au3>
#Include <File.au3>
#include <String.au3>

; Read contents of EASIndexer.log into an array
If Not _FileReadToArray('d:\easlog\EASIndexer.log', $aEASIndexerLog) Then
    ; If failed to open PSTList write an error and exit
    WriteToErrorLog('Unable to open EASIndexer.log')
    Exit
EndIf

; Create Script file to write too (any existing file will be deleted)
$file1 = FileOpen('d:\BadMsgIDs\BadMsgIDs.sql', 10)
; Write 1st line of SQL code
FileWriteLine($file1, "update ft_notify set typefld ='Z' where msgid in (")

_ArrayDisplay($aEASIndexerLog)

;do for each line in the array
For $x = 1 to $aEASIndexerLog[0] Step 1
    ; Load the log entry from the array
    $LogEntry = StringStripWS($aEASIndexerLog[$x],2)
    If StringInStr($LogEntry,'openMsg: Error working with MsgID=') <> 0 Then
        $MsgID=StringLeft(StringRight($LogEntry,129),8)
        _ArrayAdd($aAllMsgIDs, $MsgID)
    Else
        ContinueLoop
    EndIf
Next

_ArrayDisplay($aAllMsgIDs)

$aUniqueMsgIDs = _ArrayUnique($aAllMsgIDs)

_ArrayDisplay($aUniqueMsgIDs)

For $x = 1 to $aUniqueMsgIDs[0] Step 1
    FileWriteLine($file1, $aUniqueMsgIDs[$x] & ',')
Next

FileWriteLine($file1, $MsgID & ')')

FileClose($file1)
Exit

Thanks,

Phill.

Link to comment
Share on other sites

Don't use Dim, try Global:

Global $aEASIndexerLog[], $aAllMsgIDs[], $aUniqueMsgIDs[], $LogEntry, $MsgID, $file1, $LastEntry, $ErrorMsg, $NewLastEntry

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

To see what has changed I suggest to have a look at the Changelog in the help file. There you'll find a link to the script breaking changes. This are the areas where you need to brush up your scripts ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

These changes have cost me a days work so far :(

OK, I cant figure out how to change the loop so that it executes once per row of the array, the old code looked like this:

For $x = 1 to $aEASIndexerLog[0] Step 1
    ; Load the log entry from the array
    $LogEntry = StringStripWS($aEASIndexerLog[$x], $STR_STRIPTRAILING)
    If StringInStr($LogEntry, "openMsg: Error working with MsgID=") <> 0 Then
        $MsgID=StringLeft(StringRight($LogEntry,129),8)
        _ArrayAdd($aAllMsgIDs, $MsgID)
    Else
        ContinueLoop
    EndIf
Next

I think I have to change the format of For..to..step..next loop but I've looked in the help and can't find what, sorry to keep asking for help but I only write scripts occasioanly.

Thanks again.

Phill.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...