03.02 Viewing Progress and Handling Errors - AndrewMB2/Logic-Architect-for-Excel-VBA GitHub Wiki
Viewing Progress
When developing code, there is often a need to view the results as the code progresses - particularly with ArrData and RsetData (with TableData, results are visible on the worksheet). This can be done by defining a XShared object and using its ShowIE method, for example
Dim Xs as New XShared
Xs.ShowIE Ad1
This shows the contents of the ArrData object Ad1 in an Information Explorer window. It is possible to limit the number of rows displayed if required. The ShowIE line can be built into the code, but it is often more convenient to pause the code where required and then type this line in the immediate pane. This can be repeated as often as required while stepping through the code just by selecting the line in the immediate pane and pressing Enter.
If it is required to show results at every major ArrData procedure, this can be done by setting the constant DefShowMode at the top of the code of XShared to True. Then when stepping though the code one procedure at a time, at every major procedure, the results will be displayed (first 100 rows).
Handling Errors
Errors are handled in-line.
Every Xdata object has a HasError property. When an error occurs, this is set to True, an error message is produced and the procedure exits. When running another procedure, if HasError is True, the procedure exits immediately without doing anything. When running a procedure which gets data from another Xdata object, if that has a HasError value of true, then the first procedure's HasError property is set to true and the procedure exits without doing anything. As a result, it is only necessary to test HasError occasionally after a series of procedures. Normally the user would then exit, though occasionally, if the user believes the situation can be recovered, HasError can be directly reset.
Also all procedures which do not otherwise return a value will return True or False, depending on whether the procedure has run successfully or not. This provides an alternative method of testing for errors.