When performing a task that will take some time it is useful to show how long it has taken, and how long to go. In this section we will implement a countdown timer so that Sudokus can be solved 'against the clock'. If you want to implement a more general countdown timer, look here.
I'm sure you have all suffered from that installation problem where it says its 50% complete, suddenly jumps to 97% complete then starts again. This is particularly common with Microsoft applications - hence the term 'Microsoft Time'. In addition, a timer is quite often implemented as part of a loop of a process. However, in this case, since we are going to mainly be waiting for input, we wont have a processing loop to use, so we have to implement an asynchronous approach to updating our timer.
We are going to need a couple of things
One of the arguments for application.ontime is the name of the procedure that should run when the schedule time arrives (in this case the contents of pScheduleUpdateProcess). The strangeness here is that you cannot implement the called procedure as part of a class. It has to be a 'normal procedure'. Since I wanted to encapsulate all this in the cSudProgressBar class, we need a workaround. In this case, I initialize the class, passing to it the name of a 'normal procedure' that will know which class method to call. This name is stored in pScheduleUpdateProcess so it can be passed to application.Ontime. All that progressupdate does is to call the appropriate method. The key is to make sure it is a public procedure of a 'normal module'
The complete code is below, or can be downloaded as part of the Sudoku Project.
You want to learn Google Apps Script?
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now 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 > Recursion > Sudoku Generator and Solver >