Jump to content

Debug macro or command


Recommended Posts

I am a little rusty as i havent used AutoIt recently so maybe this is very easy.

I have a complex script using MS office object model. I would like to detect on which line the compiled fails when run from the compiled  EXE file.

For example:

$oOApp = 0
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$oOApp.CreateItem ($olMailItem)
Func MyErrFunc()
 MsgBox (0,"We intercepted an Error" & @ErrorLine ,$oMyError.description& @CRLF & $oMyError.windescription,15)
Endfunc
Exit

So when i run this code i would like to get that it failed on line 3.

Any idea how i can accomplish that ?

Link to comment
Share on other sites

Its (very very hard) not really possible to correlate what line a compiled EXE fails on with what line that is on a script. All includes are inserted above your code... and then some other magic happens AFAIK.  If you're unable to run an uncompiled script, you could either insert message boxes, or write a quick function for writing a log like:

Func WriteLog($sText)
    Local $sTmp = ""
    If Not FileCreate($L_LogPath, _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & "  Log - First Run" & @CRLF) Then

        If Not $bReportsOnly Then MsgBox($MB_ICONERROR, "", "No log file exists, and an error occured while trying to create one!!!")
        Return False
    EndIf

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($L_LogPath, $FO_APPEND)
    If $hFileOpen = -1 Then
        If Not $bReportsOnly Then MsgBox($MB_ICONERROR, "", "An error occurred when reading the file.")
        Return False
    EndIf

    If Isarray($sText) Then
        Local $i
        For $i = 0 to UBound($sText)-1
            $sTmp &= $sText[$i] & "  "
        Next
        $sText = $sTmp
    EndIf

    FileWriteLine($hFileOpen, _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & "  " & $sText)
    FileClose($hFileOpen)
EndFunc

This is what I use in my complex programs, works great.

Edited by kaisies
Link to comment
Share on other sites

I don't get how to use it. What should i do ? Call the function after every line of code ? What is sText ?

​This is a function that writes to a text file (log file) that you specifiy with $L_LogPath.   $sText is what is passed to that function.

So after each (Major) point of failure in your program, you can write to this log whatever you want, like... Created this object, and then you writelog that it succeeded.  Or anything relevant to user interaction (user clicked this button, or that button, or selected these things, which now im going to parse, and then writelog the result)

Link to comment
Share on other sites

A compiled script always returns -1 as line number.
Either modify the script to catch all errors (preferred method) or set a variable to a value denoting the position in your script and display this value when a COM error handler is being called.
 

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 don't think i understand this part : 'or set a variable to a value denoting the position in your script '

Could you please modify my start post script so i can see what you mean ?

Edited by Juvigy
typo
Link to comment
Share on other sites

Example:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$sSection = "First section"
Some COM stuff
$sSection = "Second section"
Some other COM stuff

Func MyErrFunc()
    MsgBox (0,"Error", "We intercepted an error in section " & $sSection)
Endfunc
Exit

 

 

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

Thanks , it seems i will have to go the hard way.

BTW - i found where it failed. If outlook is not already open the bellow code fails on the last line:

$oOApp = ObjCreate("Outlook.Application")
$oOMail = $oOApp.CreateItem ($olMailItem)
$oDoc = $oOMail.GetInspector.WordEditor

I could do a shellexecute(outlook) but , I really would like to avoid that.  Any idea why it fails ?

Link to comment
Share on other sites

Why don't you use my OutlookEX UDF? Error handling is already built in. 

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

How does my UDF "break" your Outlook?

Which version?

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

2013 , i think it is something about the "create test environment" which started duplication of mails and calendars. I don't remember exact details anymore , but restarting and deleting test env. calendars didn't help.

Link to comment
Share on other sites

The test environment is a new folder with contacts, notes, mails, calendar entries etc. If you delete this folder or run _OL_TestEnvironment.au3 and press the delete button then the test environment should be gone.
I only have Outlook 2010 so would be grateful if someone could assist me in improving it for Outlook 2013.

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