Jump to content
Juvigy

Debug macro or command

Recommended Posts

Juvigy

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 ?

Share this post


Link to post
Share on other sites
kaisies

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

Share this post


Link to post
Share on other sites
Juvigy

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

Share this post


Link to post
Share on other sites
kaisies

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)

Share this post


Link to post
Share on other sites
Juvigy

I need something better. This is good for small scripts , but i need something more elegant.

Share this post


Link to post
Share on other sites
kaisies

Good luck finding something that fits your needs.

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Juvigy

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Juvigy

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 ?

Share this post


Link to post
Share on other sites
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Juvigy

Because i dont know why , but it brakes my outlook. 

Share this post


Link to post
Share on other sites
water

How does my UDF "break" your Outlook?

Which version?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Juvigy

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.

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

×