Sign in to follow this  
Followers 0
bourny

OutlookEX problem

9 posts in this topic

 I am using your outlookEX provided by "Water"  to much success however I have come across an issue.  I have a script which simply reads the content of an inbox and then interrogates the result.  It appears if I run the script against a subfolder in the inbox I get no issues.  If I then point it to the inbox root which is being updated often with new email I get errors from the below line

"C:\Program Files (x86)\AutoIt3\Include\outlookEX.au3 (2678) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value
^ ERROR" 

I believe the reason why this occurs is the inbox grows in size with new emails coming in while I am interrogating it with the below command

$oOutlook = _OL_Open()
 $Folder = _OL_FolderAccess($oOutlook, "", $olFolderInbox)

If I copy all the emails into a subfolder in the inbox and point the above line to the subfolder it does not fail backing my theory this is down to the inbox receiving updates and the array in the outlookex code not handling this.

The line error in the outlookex that triggers the above error is line 2673 of outlookex.  I have included below a snippet of outlookEX where the error occurs

The line that triggers the error is "$aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value"

What is interesting is if I change the "$icounter +=1" to $icounter = 1 I never get the error but the result I get back is different so I clearly cannot mess about with this value.  I believe this is the fact that the $aReturnProperties[0] is defined and this is a static value and may need to be a dynamic ubound value that is checked each time the loop is processed to stop it getting annoyes as the mailbox grows past the initial ubound value when the loop started

I have attached a copy of WATERS outlookEX function that I am using

For $oItem In $oItems
        If $oItem.Class <> $iObjectClass Then ContinueLoop
        ; Get all properties of first item and check for existance and correct case
        If BitAND($iFlags, 4) <> 4 And Not $bChecked Then
            If Not __OL_CheckProperties($oItem, $aReturnProperties, 1) Then Return SetError(@error, @extended, "")
            $bChecked = True
        EndIf
        If $sSearchName <> "" And StringInStr($oItem.ItemProperties.Item($sSearchName).value, $sSearchValue) = 0 Then ContinueLoop
        ; Fill array with the specified properties
        $iCounter += 1
        If BitAND($iFlags, 4) <> 4 Then
            For $iIndex = 1 To $aReturnProperties[0]
                $aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value
                If @error Then Return SetError(4, @error, "")
                If BitAND($iFlags, 2) = 2 And $iCounter = 1 Then $aItems[0][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).name
            Next
        EndIf
        If BitAND($iFlags, 4) <> 4 And BitAND($iFlags, 2) <> 2 Then $aItems[0][0] = $iCounter
    Next

OutlookEX.au3

Share this post


Link to post
Share on other sites



I assume you are talking about function _OL_ItemFind?

As you can see on page 1 there is a bug in this function when new mails arrive while processing the inbox.

If I'm correct I can provide an updated version.


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

you are correct.  Have been working from a subfolder that never changes until recently I pointed it at the inbox root and cannot settle it down.  Some times it works but most times throws up the error.  Am I correct in this is the reason for the issue with the mailbox growing past the initial ubound value set when entering the loop.

Share this post


Link to post
Share on other sites

Sorry Water.  Not sure if you are pointing me to the fix on "Page 1" or I need to obtain the fix from you or the updated version if you have one.  I am currently using 0.9.0 if that helps

Thanks

Share this post


Link to post
Share on other sites

On page 1 you'll only find the description of the bug.

I will post the fixed function tomorrow.


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

Thanks for your assistance

Share this post


Link to post
Share on other sites

This is the modified _OL_ItemFind function:

; #FUNCTION# ====================================================================================================================
; Name ..........: _OL_ItemFind
; Description ...: Finds items (contacts, appointments ...) returning an array of all specified properties.
; Syntax.........: _OL_ItemFind($oOL, $vFolder[, $iObjectClass = Default[, $sRestrict = ""[, $sSearchName = ""[, $sSearchValue = ""[, $sReturnProperties = ""[, $sSort = ""[, $iFlags = 0[, $sWarningClick = ""]]]]]]]])
; Parameters ....: $oOL               - Outlook object returned by a preceding call to _OL_Open()
;                  $vFolder           - Folder object as returned by _OL_FolderAccess or full name of folder where the search will be started.
;                  +If you want to search a default folder you have to specify the folder object.
;                  $iObjectClass      - Optional: Class of items to search for. Defined by the Outlook OlObjectClass enumeration (default = Default = $olContact)
;                  $sRestrict         - Optional: Filter text to restrict number of items returned (exact match). For details please see Remarks
;                  $sSearchName       - Optional: Name of the property to search for (without brackets)
;                  $sSearchValue      - Optional: String value of the property to search for (partial match)
;                  $sReturnProperties - Optional: Comma separated list of properties to return (default = depending on $iObjectClass. Please see Remarks)
;                  $sSort             - Optional: Property to sort the result on plus optional flag to sort descending (default = None). E.g. "[Subject], True" sorts the result descending on the subject
;                  $iFlags            - Optional: Flags to set different processing options. Can be a combination of the following:
;                  |  1: Subfolders will be included
;                  |  2: Row 1 contains column headings. Therefore the number of rows/columns in the table has to be calculated using UBound
;                  |  4: Just return the number of records. You don't get an array, just a single integer denoting the total number of records found
;                  $sWarningClick     - Optional: The entire path (drive, directory, file name and extension) to 'OutlookWarning2.exe' or another exe with the same function (default = None)
; Return values .: Success - One based two-dimensional array with the properties specified by $sReturnProperties
;                  Failure - Returns "" and sets @error:
;                  |1 - You have to specifiy $sSearchName AND $sSearchValue or none of them
;                  |2 - $sWarningClick not found
;                  |3 - Error accessing the specified folder. See @extended for errorcode returned by _OL_FolderAccess
;                  |4 - Error accessing specified property. For details check @extended
;                  |1xx - Error checking $sReturnProperties as returned by __OL_CheckProperties. @extended is the number of the property in error (zero based)
; Author ........: water
; Modified ......:
; Remarks .......: Be sure to specify the values in $sReturnProperties and $sSearchName in correct case e.g. "FirstName" is valid, "Firstname" is invalid
;+
;                  $sRestrict: Filter can be a Jet query or a DASL query with the @SQL= prefix. Jet query language syntax:
;                  Restrict filter:  Filter LogicalOperator Filter ...
;                  LogicalOperator:  And, Or, Not. Use ( and ) to change the processing order
;                  Filter:           "[property] operator 'value'" or '[property] operator "value"'
;                  Operator:         <, >, <=, >=, <>, =
;                  Example:          "[Start]='2011-02-21 08:00' And [End]='2011-02-21 10:00' And [Subject]='Test'"
;                  See: http://msdn.microsoft.com/en-us/library/cc513841.aspx              - "Searching Outlook Data"
;                       http://msdn.microsoft.com/en-us/library/bb220369(v=office.12).aspx - "Items.Restrict Method"
;+
;                  N.B.: Pass time as HH:MM, HH:MM:SS is invalid and returns no result
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _OL_ItemFind($oOL, $vFolder, $iObjectClass = Default, $sRestrict = "", $sSearchName = "", $sSearchValue = "", $sReturnProperties = "", $sSort = "", $iFlags = 0, $sWarningClick = "")

    Local $bChecked = False, $oItems, $aTemp, $iCounter = 0, $oItem
    If $sWarningClick <> "" Then
        If FileExists($sWarningClick) = 0 Then Return SetError(2, 0, "")
        Run($sWarningClick)
    EndIf
    If $iObjectClass = Default Then $iObjectClass = $olContact ; Set Default ObjectClass
    ; Set default return properties depending on the class of items
    If StringStripWS($sReturnProperties, 3) = "" Then
        Switch $iObjectClass
            Case $olContact
                $sReturnProperties = "FirstName,LastName,Email1Address,Email2Address,MobileTelephoneNumber"
            Case $olDistributionList
                $sReturnProperties = "Subject,Body,MemberCount"
            Case $olNote, $olMail
                $sReturnProperties = "Subject,Body,CreationTime,LastModificationTime,Size"
            Case Else
        EndSwitch
    EndIf
    If Not IsObj($vFolder) Then
        $aTemp = _OL_FolderAccess($oOL, $vFolder)
        If @error Then Return SetError(3, @error, "")
        $vFolder = $aTemp[1]
    EndIf
    If ($sSearchName <> "" And $sSearchValue = "") Or ($sSearchName = "" And $sSearchValue <> "") Then Return SetError(1, 0, "")
    Local $aReturnProperties = StringSplit(StringStripWS($sReturnProperties, 8), ",")
    Local $iIndex = $aReturnProperties[0]
    If $aReturnProperties[0] < 2 Then $iIndex = 2
    If StringStripWS($sRestrict, 3) = "" Then
        $oItems = $vFolder.Items
    Else
        $oItems = $vFolder.Items.Restrict($sRestrict)
    EndIf
    Local $iItems = $oItems.Count
    Local $aItems[$iItems + 1][$iIndex] = [[0, $aReturnProperties[0]]]
    If BitAND($iFlags, 4) <> 4 And $sSort <> "" Then
        $aTemp = StringSplit($sSort, ",")
        If $aTemp[0] = 1 Then
            $oItems.Sort($sSort)
        Else
            $oItems.Sort($aTemp[1], True)
        EndIf
    EndIf
    For $i = 1 To $iItems
        $oItem = $oItems.Item($i)
        If $oItem.Class <> $iObjectClass Then ContinueLoop
        ; Get all properties of first item and check for existance and correct case
        If BitAND($iFlags, 4) <> 4 And Not $bChecked Then
            If Not __OL_CheckProperties($oItem, $aReturnProperties, 1) Then Return SetError(@error, @extended, "")
            $bChecked = True
        EndIf
        If $sSearchName <> "" And StringInStr($oItem.ItemProperties.Item($sSearchName).value, $sSearchValue) = 0 Then ContinueLoop
        ; Fill array with the specified properties
        $iCounter += 1
        If BitAND($iFlags, 4) <> 4 Then
            For $iIndex = 1 To $aReturnProperties[0]
                $aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value
                If @error Then Return SetError(4, @error, "")
                If BitAND($iFlags, 2) = 2 And $iCounter = 1 Then $aItems[0][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).name
            Next
        EndIf
        If BitAND($iFlags, 4) <> 4 And BitAND($iFlags, 2) <> 2 Then $aItems[0][0] = $iCounter
    Next
    If BitAND($iFlags, 4) = 4 Then
        ; Process subfolders
        If BitAND($iFlags, 1) = 1 Then
            For $vFolder In $vFolder.Folders
                $iCounter += _OL_ItemFind($oOL, $vFolder, $iObjectClass, $sRestrict, $sSearchName, $sSearchValue, $sReturnProperties, $sSort, $iFlags, $sWarningClick)
            Next
        EndIf
        Return $iCounter
    Else
        ReDim $aItems[$iCounter + 1][$aReturnProperties[0]] ; Process subfolders
        If BitAND($iFlags, 1) = 1 Then
            For $vFolder In $vFolder.Folders
                $aTemp = _OL_ItemFind($oOL, $vFolder, $iObjectClass, $sRestrict, $sSearchName, $sSearchValue, $sReturnProperties, $sSort, $iFlags, $sWarningClick)
                __OL_ArrayConcatenate($aItems, $aTemp, $iFlags)
            Next
        EndIf
        Return $aItems
    EndIf

EndFunc   ;==>_OL_ItemFind

I hope it solves your problem.

1 person likes this

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

I believe that has resolved the problem.  Thank you for your efforts sorting this one out for me.

Share this post


Link to post
Share on other sites
:D

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

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
Sign in to follow this  
Followers 0