Jump to content

need error checking help


Recommended Posts

Hello all,

here's a function I created to find local outlook pst files and close them.

#include <OutlookEX.au3>

Func DisconnectPSTEX()
Local $aStores = _OL_StoreGet($oOL)
    For $i = 1 to $aStores[0][0]
        If $aStores[$i][4] = True Then
        _OL_PSTClose($oOL,$aStores[$i][0])
        EndIf
    Next
_OL_Close($oOL)
$objOutlook.Quit
EndFunc

I have encountered that my code crashes when it's faced with a legacy 'public folders' exchange folder.

How do I input error checking with would allow my code to continue if it crashes?

like 'on error' - 'display MsgBox' then FuncEnd - continue

Link to comment
Share on other sites

The OutlookEX UDF has a _OL_ErrorNotify function. This handles errors when running AutoIt < 3.3.9.0

Give

_OL_ErrorNotify(1)

a try.

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

Which version of the UDF do you use? Must be 0.7.1.1. or older. Version 0.8.0.1 and later have the function included.

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

I dont think the error notify is what I'm looking for.

I just need it stop the function, if there is an error and continue with the rest of the script.

You need to grab the COM error. That is what _OL_ErrorNotify is for. You then can check for @error <> 0 and exit your script.

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

What you need is a COM error handler. This is what _OL_ErrorNotify does. _OL_ErrorNotify is part of the latest version of the UDF 0.9.0.0.
When _OL_ErrorNotify grabs a COM error it allows the script to continue with the statement following the statement causing the COM error. So you need to check for an error and if found exit the function

_OL_PSTClose(...)
If @error Then Return
Edited by water

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

#include <OutlookEX.au3>

Func DisconnectPSTEX()
Local $aStores = _OL_StoreGet($oOL)
For $i = 1 to $aStores[0][0]
If $aStores[$i][4] = True Then
_OL_PSTClose($oOL,$aStores[$i][0])
EndIf
Next
_OL_Close($oOL)
$objOutlook.Quit
EndFunc


 

 

 

What you need is a COM error handler. This is what _OL_ErrorNotify does. _OL_ErrorNotify is part of the latest version of the UDF 0.9.0.0.
When _OL_ErrorNotify grabs a COM error it allows the script to continue with the statement following the statement causing the COM error. So you need to check for an error and if found exit the function

_OL_PSTClose(...)
If @error Then Return

Can you please take my reference code, and show me how it's done?

Link to comment
Share on other sites

#include <OutlookEX.au3>

_OL_Open(...)
_OL_ErrorNotify(1)
DisconnectPSTEX()
_OL_Close(...)
Exit

Func DisconnectPSTEX()
    Local $aStores = _OL_StoreGet($oOL)
    For $i = 1 to $aStores[0][0]
        If $aStores[$i][4] = True Then
            _OL_PSTClose($oOL,$aStores[$i][0])
            If @error Then Return
        EndIf
    Next
EndFunc

Wasn't that easy?

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

#include <OutlookEX.au3>

_OL_Open(...)
_OL_ErrorNotify(1)
DisconnectPSTEX()
_OL_Close(...)
Exit

Func DisconnectPSTEX()
    Local $aStores = _OL_StoreGet($oOL)
    For $i = 1 to $aStores[0][0]
        If $aStores[$i][4] = True Then
            _OL_PSTClose($oOL,$aStores[$i][0])
            If @error Then Return
        EndIf
    Next
EndFunc

Wasn't that easy?

no, becuase when I compile it says that _OL_ErrorNotify(1) is unknown

Link to comment
Share on other sites

Then please show me the first few lin es of the UDF.

Mine looks like this:

#Tidy_Parameters= /gd 1  /gds 1 /nsdp
#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=Y
#include-once
#include <Array.au3>
#include <Date.au3>
#include <File.au3>
#include <OutlookExConstants.au3>
; #INDEX# =======================================================================================================================
; Title .........: Microsoft Outlook Function Library (MS Outlook 2003 and later)
; AutoIt Version : 3.3.9.2 (New COM error handler), runs with 3.3.8.1 too
; UDF Version ...: 0.9.1.0
; Language ......: English
; Description ...: A collection of functions for accessing and manipulating Microsoft Outlook
; Author(s) .....: wooltown, water
; Modified.......: 20130319 (YYYYMMDD)
; Contributors ..: progandy (CSV functions taken and modified from http://www.autoitscript.com/forum/topic/114406-csv-file-to-multidimensional-array)
;                  Ultima, PsaltyDS for the basis of the __OL_ArrayConcatenate function
; Resources .....: Outlook 2003 Visual Basic Reference: http://msdn.microsoft.com/en-us/library/aa271384(v=office.11).aspx
;                  Outlook 2007 Developer Reference:    http://msdn.microsoft.com/en-us/library/bb177050(v=office.12).aspx
;                  Outlook 2010 Developer Reference:    http://msdn.microsoft.com/en-us/library/ff870432.aspx
;                  Outlook Examples:                    http://www.vboffice.net/sample.html?cmd=list&mnu=2
; ===============================================================================================================================

#region #VARIABLES#
; #VARIABLES# ===================================================================================================================
Global $__iOL_Debug = 0 ; Debug level. 0 = no debug information, 1 = Debug info to console, 2 = Debug info to MsgBox, 3 = Debug Info to File
Global $__sOL_DebugFile = @ScriptDir & "\Outlook_Debug.txt" ; Debug file if $__iOL_Debug is set to 3
Global $__oOL_Error ; COM Error handler
Global $__bOL_AlreadyRunning = False ; Is Outlook already running?
; ===============================================================================================================================
#endregion #VARIABLES#

; #CURRENT# =====================================================================================================================
;_OL_Open
;_OL_Close
;_OL_ErrorNotify

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

my bad..... due to our win 7 admin rights settings, I thought I copied the new udf into the include folder, but in reality it didnt.

so, the errornotity is working for me now.. and now I just have on more issue. And I'm sure it's due to me not understanding arrays.

I need my code to comb through all the data stores and only disconnect PST files. But now, I get an error when it tries to disconnect the local OST file. How do I get this to not look at OSt files and only PST?

#include <OutlookEX.au3>
Global $oOL = _OL_Open(True)
_OL_ErrorNotify(2)
DisconnectPSTEX()

Exit

Func DisconnectPSTEX()
    Local $aStores = _OL_StoreGet($oOL)
    For $i = 1 to $aStores[0][0]
        _ArrayDisplay($aStores)
        If $aStores[$i][4] = True Then
            _OL_PSTClose($oOL,$aStores[$i][0])
        EndIf
    Next
    _OL_Close($oOL)
EndFunc
Link to comment
Share on other sites

The last 4 characters of $aStores[$i][2] should either be ".pst" or ".ost".

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

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...