FrancescoDiMuro Posted January 20, 2017 Share Posted January 20, 2017 Hi guys I'd like to know what's the best way to error checking/debbuging... Should I use MsgBoxes or ConsoleWrite? Which "errors" are sensibles for the users? Which "errors" should be prompted to the user and which should not ( MsgBoxes and ConsoleWrite). Thanks for your help Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
weevil Posted January 20, 2017 Share Posted January 20, 2017 There's 2 different questions here. First of all when you're still developing, I use a combination of ToolTip and ConsoleWrite to know what's what and where when I'm developing. The second is notifying users when an error actually occurs that will have problems for them. You should have a general idea of what can/will error. For this you should write to a log. Check out this function: https://www.autoitscript.com/autoit3/docs/libfunctions/_FileWriteLog.htm You can then use MsgBoxes with the same information or something more "friendly" for an end users to know that it's broken. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 20, 2017 Author Share Posted January 20, 2017 @weevil Thanks for your reply buddy! I have ( It's not a problem ) like 10+ functions which set the error flag, should I prompt a MessageBox for each function? I.E. : _Excel_RangeWrite() For 10 times, not in a Loop... Should I prompt a MessageBox for each of them? Thanks Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
weevil Posted January 20, 2017 Share Posted January 20, 2017 Not unless there's specific user action based on the results of each error. If it errors and the whole thing just collapses and you have to start again, 1 will suffice. This is more of a UX design decision rather than any coding practices. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 20, 2017 Author Share Posted January 20, 2017 (edited) So, in this case, I could add only 1 error checking at the end of the _Excel_RangeWrite() lines, right? _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_CodiceNuovoProdotto), "A" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_Marca), "B" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_Quantita), "C" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_Scaffale), "D" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($edit_Descrizione), "E" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_Costo), "F" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($edit_Note), "G" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($edit_Info), "H" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, GUICtrlRead($input_CodiceABarre), "I" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sDataOraModifica, "J" & $iIndiceRigaVuota) If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) Thanks Edited January 20, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
weevil Posted January 20, 2017 Share Posted January 20, 2017 Yea, create an error handling function: func excelError() ConsoleWrite("you broke it you wally") & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) endFunc This will tidy up the code, but from the looks of that function you need to have an @error if you want each individual function to have its own error handling. Looking at it, I'm sure more expert coders will give some pointers on how to tidy this up, perhaps with an array for each cell column? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 20, 2017 Author Share Posted January 20, 2017 @weevil Quote Looking at it, I'm sure more expert coders will give some pointers on how to tidy this up, perhaps with an array for each cell column? I don't know, by the way what I'm trying to do is have an error management, in order to, in case of error, identify the row and/or the function that has returned an error, and, I don't know if I should prompt to the user... In case of one of the _Excel_RangeWrite() fails, should I prompt to the user the error? And/or, how does error flag work? If I put If(@error) Then ConsoleWrite("Errore durante la scrittura sul foglio Excel!" & " " & "Errore: " & @error & "Linea: " & @ScriptLineNumber) at the end of the _Excel_RangeWrite(), and the first of them cause an error, and the second does too, which @SriptLineNumber will catch the error flag? Sorry, but I'm a bit confused on how errors work, so I'm asking Thanks for your time @weevil! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted January 20, 2017 Share Posted January 20, 2017 As you are writing data to a contiguous range of cells you could create an array and use a single call _Excel_RangeWrite. To handle errors I would first decide how severe an "error" is. I very much like the way IBM used it in the old mainframe days. I - Information. Processing has ended and everything worked fine W - Warning. Processing has ended but there was a problem which could be solved by the program (a file already existed and the script had to overwrite it) E - Error. Processing could not be done successfully. You need to solve a problem so processing can continue. All files remain in a defined state. S - Severe. The program ended in an abnormal way (no error handling and system cleanup was possible). Some files may now have an undefined state. When an E or S error happened you should not allow the script to continue. Exit on the first occurrence of the error. dmob 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
FrancescoDiMuro Posted January 20, 2017 Author Share Posted January 20, 2017 (edited) Good morning @water! You are my best favourite programmer in this forum, 'cause your explanations are clear as... water So, for this: Should I create something like an array containing the variabile to write and the position where to write my data... Something like a 2D array? It was you were meaning? A big thanks, man! EDIT: So, for E and S, I should prompt a MsgBox for the error, did I undertand right? Edited January 20, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted January 20, 2017 Share Posted January 20, 2017 Check example 3 in the help file for _Excel_RangeWrite to get an idea how to write a 2D array to Excel. I would use MsgBox to inform the user when an E or S error happened and then Exit the script. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 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