FrancescoDiMuro

How to do Error Checking/Debugging?

10 posts in this topic

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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

@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 :D 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

@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 :D
Thanks for your time @weevil!


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

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.

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Good morning @water! :D
You are my best favourite programmer in this forum, 'cause your explanations are clear as... water :D
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! :D 

EDIT: So, for E and S, I should prompt a MsgBox for the error, did I undertand right? :) 
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#10 ·  Posted

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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