Identifying rogue cases - (by that I mean a combination of circumstances that cause a normally well behaved procedure to take forever), is very simple using these profiling tools. For the sake of this example, I'm assuming you have read about profiling, downloaded and added profiling using the autoprofiler, played around with it and come up with a section of code that has a wide variance of execution times, and you want to understand which iterations are taking a long time.
Lets look at an example
' some loop
' code A to be investigated
We have identified that sometimes the section of code between our start and finish timers takes a long time to execute. We want to halt execution and debug when it happens.
First set up a cproctimer class to use.
... assign the one being monitored
... this will halt execution when the time spent on any particular iteration is more than .5 second
Note that when you break execution, the timer continues so every time you look at cTimer.soFar it will have increased. If this matters, pause the timer with ctimer.pause before breaking code execution.
Another useful one would be number of iterations, as below where execution will break when the number of times we have been in this loop is 5000 or more.
Clearly this gives a powerful tool to break execution programatically if certain activities take longer than expected. See here for more on the cproctimer class.
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'Reilly, Amazon and all good bookshops. You can also read a preview on O'Reilly
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Optimization >