Riviera_Phill

Problem using _ArrayAdd

8 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
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.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Humm, looks like quite a bit changed between versions, I think I'm going to have to re-write this from the ground up rather than trying to edit it.

Thanks for your help guys.

Phill.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Sorry, ignor that last message, I've found it, I have to use UBound.

Phill.

Share this post


Link to post
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