Lights_On Posted January 23, 2016 Share Posted January 23, 2016 Hi All, I have an issue with AutoIT3 crashing at the end of my script - all works fine when debugging however. Allow me to add a little further detail. I am running V3.3.14.2 on W7 x84. My script predominately works with Excel files and is in the region of 3000 lines. I have a custom debug set up (sounds better than it is - it just writes errors to a log) and I have tracked the script and now I can say there are no errors that I know of. If I run the scrip all runs until the very end where it crashes - attached is the message thrown. The odd part is, that if I add trace lines from the tools menu to try and debug further, and watch the script run while it out puts info, the issue disappears (does not happen) - the scrip runs smoothly from start to finish as one would expect / as was intended. So - is my issue my script - or AutoIT / windows? Thank you in advance for any help you may be able to offer. Link to comment Share on other sites More sharing options...
water Posted January 23, 2016 Share Posted January 23, 2016 Do you properly release all ressources when ending the script? Do you use the Excel UDF that comes with AutoIt in 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 - 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...
Lights_On Posted January 23, 2016 Author Share Posted January 23, 2016 Yes and yes - as far as I'm aware. I have checked that all bookopen commands have a subsequent bookclose command. I mainly use functions in the script and each function opens an excel instance and also closes one with excelopen excelclose. I have logged all error checks and all opens and closes of an instance or book and all reports as working as expected. I use the UDF included in the download and include it appropriately. Link to comment Share on other sites More sharing options...
water Posted January 23, 2016 Share Posted January 23, 2016 Not easy to debug this problem without seeing your code. Can you strip down your script and still reproduce the problem? If yes, please post this reproducer so we have something to play with. 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 Hi Water, Sounds fair. I have some time later today so will start stripping back the code. If the problem clears I shall post the of ofending code apparently causing the issue, if the issue remains I will hopfuly have less code that I can share. Whilst I'm here would it be possible to confirm the correct procedure for book open then close? I currently open an instance of excel, then open a book, then do what I need, then close book (using a save syntax when neede) then close excel. Is this correct? Should I use an excel save before close? Thank you for you time and help. Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 (edited) Your procedure seems sensible. BTW: Do you check the return values to grab errors? Edited January 24, 2016 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 - 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 I have found a section of code that when removed allows for the script to complete - when added I get the fail. So at least a starting point. before I post the code I will take some time to go over it a few times and try some changes first to double check i'm not making any silly errors. The error reporting on it however throws no errors. I will update shortly with findings and if still no luck will post the code. I do not check return values - not sure how. I check errors to my log as per below method: _Excel_RangeWrite($Report_Sheet, Default, $arr[32], "A2:X2") If @error Then _log('ERROR - Range write was not sucsessful, the @error code is: ' & @error) Else _log('Range write completed okay') EndIf I would welcome an example of how to catch a return and can add it in to my log for info gathering to help identify possible issues. Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 (edited) What is the value of @error and @extended? Edited January 24, 2016 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 - 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 The return values are all successful - so no errors reported. Just the crash happens - unless I am miss understanding you? I have made progress however. I have narrowed down the code further. the lines that cause the crash when used are: While _Excel_RangeRead($Workbook2write, Default, "H" & $arr[23], "1") <> ("Net") ;if cell does not have 'Net' in it $arr[23] = $arr[23] + "1" WEnd I have just tried adding a sleep to it: While _Excel_RangeRead($Workbook2write, Default, "H" & $arr[23], "1") <> ("Net") ;if cell does not have 'Net' in it $arr[23] = $arr[23] + "1" Sleep(500) WEnd but this did not help. Just to add reminder - this code works fin in the script the first two times it is called upon. It is only the third time it is called that it seems to be the culprit of the issue? Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 What do you try to achieve with this code? Retrieve the first row in column "H" without "Net" in it? The problem with your code is, that it will read data even if the index exceeds the used range or even the max. number of rows allowed by Excel. About how many rows and columns do we talk here? Means: How big is your worksheet? 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 I seek to start checking each cell downward in column H one by one until a cell with 'Net' in it is found. Once found the script knows the row number this is and records it at: $arr[23] I use this data later. The number of rows it counts down would never exceed 200 (at a guess) on average it will never count down more than 50 cells. Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 $aColumnH = _Excel_RangeRead($Workbook2write) If @error Then ; An error occurred. Do what needs to be done here EndIf $bFound = False For $i = 0 To UBound($aColumnH, 1) - 1 If $a[$i] = "Net" Then $arr[23] = $i + 1 $bFound = True ExitLoop EndIf Next If Not $bFound Then ; No cell with "Net" found. Do what needs to be done in this case here EndIf I suggest the following code. Makes error checking a bit easier and should be faster too. 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 Thank you. This is a bit above me. I simply added it and ran the script. I get error 'variable used with out being declared' at: If $a[$i] = "Net" Then I will try playing with it to understand it as have just inserted it currently. Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 My bad. Should be: $aColumnH = _Excel_RangeRead($Workbook2write, Default, "H1:H" & $oWorkbook.ActiveSheet.UsedRange.Rows.count) ; Read column H from the first to the last row into a 1D array. If @error Then ; An error occurred. Do what needs to be done here EndIf $bFound = False For $i = 0 To UBound($aColumnH, 1) - 1 ; Process all cells of the array If $aColumnH[$i] = "Net" Then $arr[23] = $i + 1 ; Set the index of the first cell containing "Net" $bFound = True ; Set the flag that a cell with "Net" was found ExitLoop ; End processing the array EndIf Next If Not $bFound Then ; If none of the cells contains "Net" ; No cell with "Net" found. Do what needs to be done in this case here EndIf I have added some comments. You need to decide how your script should act when no cell with "Net" was found. Set the index to 1? Exit with an error ... 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 Made some amendments - not sure if I was supposed to? $aColumnH = _Excel_RangeRead($Workbook2write, Default, "H" & $arr[23]) If @error Then _log('ERROR - read range failed, the @error code is: ' & @error) Else _log('Read range was sucsessful') EndIf $bFound = False For $i = 0 To UBound($aColumnH, 1) - 1 If $arr[$i] = "Net" Then $arr[23] = $i + 1 $bFound = True ExitLoop EndIf Next If Not $bFound Then _log('ERROR - the word Net not found in cell') EndIf with this in the script completes but the cell in column H with 'Net' in is - I assume - not found? Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 Because you only read a single cell. Could you please grab my last code and add your amendments? 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 I have to admit - I admire your speed of understanding things! I used the below: $aColumnH = _Excel_RangeRead($Workbook2write, Default, "H1:H" & $Workbook2write.ActiveSheet.UsedRange.Rows.count) ; Read column H from the first to the last row into a 1D array. If @error Then _log('ERROR - an error was found reading the range') EndIf $bFound = False For $i = 0 To UBound($aColumnH, 1) - 1 ; Process all cells of the array If $aColumnH[$i] = "Net" Then $arr[23] = $i + 1 ; Set the index of the first cell containing "Net" $bFound = True ; Set the flag that a cell with "Net" was found ExitLoop ; End processing the array EndIf Next If Not $bFound Then ; If none of the cells contains "Net" _log('ERROR - No Net cell found in range') EndIf And I am delighted to say all works as needed. the script no longer crashes and i get the results I need. Thank you. I need to tidy the above with more informative error reporting etc. but as it stands it works. My question before I study it further is why? what was different between my way of doing it and yours that caused it to crash the way I did it? I have a similar loop earlier in my scrip and that has no issues? so why did this one - and may I get troubles with the other in the future... all good use for more learning for me. I appreciate the support. Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 Usually AutoIt scripts do not crash the way your script crashed. Maybe your script ran into an infinite loop and caused so many Excel exceptions that there was some kind of overflow ... don't know. As you see from my example I do a lot of error checking. That's what I suggest for the future! 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...
water Posted January 24, 2016 Share Posted January 24, 2016 Usually AutoIt scripts do not crash the way your script crashed. Maybe your script ran into an infinite loop and caused so many Excel exceptions that there was some kind of overflow ... don't know. As you see from my example I do a lot of error checking. That's what I suggest for the future! 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...
Lights_On Posted January 24, 2016 Author Share Posted January 24, 2016 Okay - sounds fair. I thought I had been logging and error reporting quite well but I agree I can improve. I will do some further reading around this and add to my script. Thank you. 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