Juvigy Posted May 29, 2015 Share Posted May 29, 2015 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 ExitSo 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 More sharing options...
kaisies Posted May 29, 2015 Share Posted May 29, 2015 (edited) 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) EndFuncThis is what I use in my complex programs, works great. Edited May 29, 2015 by kaisies Link to comment Share on other sites More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 I don't get how to use it. What should i do ? Call the function after every line of code ? What is sText ? Link to comment Share on other sites More sharing options...
kaisies Posted May 29, 2015 Share Posted May 29, 2015 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 More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 I need something better. This is good for small scripts , but i need something more elegant. Link to comment Share on other sites More sharing options...
kaisies Posted May 29, 2015 Share Posted May 29, 2015 Good luck finding something that fits your needs. Link to comment Share on other sites More sharing options...
water Posted May 29, 2015 Share Posted May 29, 2015 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 (edited) 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 May 29, 2015 by Juvigy typo Link to comment Share on other sites More sharing options...
water Posted May 29, 2015 Share Posted May 29, 2015 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 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.WordEditorI 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 More sharing options...
water Posted May 29, 2015 Share Posted May 29, 2015 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 Because i dont know why , but it brakes my outlook. Link to comment Share on other sites More sharing options...
water Posted May 29, 2015 Share Posted May 29, 2015 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Juvigy Posted May 29, 2015 Author Share Posted May 29, 2015 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 More sharing options...
water Posted May 29, 2015 Share Posted May 29, 2015 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now