Tuesday, January 23, 2018

VBA Pomodoro Timer

While learning about how I can improve my knowledge and myself, I discovered something called the pomodoro technique. Pomodoro is the italian word for Tomato, and the technique was named such because the creator, Francesco Cirillo, used a tomato shaped timer.

If you are unfamiliar with this technique, it is pretty simple. You write a list of things you wish to get done. After that you set a timer for 25minutes and work on a single one of your items until the timer is finished. If you finish your task before the timer is up, you continue to work on bettering yourself or improving your work until the timer is up. Once the timer is up you take a short, 3-5 minute break. Every fourth break, however, is a longer break--about 15-30 minutes. You then reset the timer and move on to your next item. This is repeated until all of your items are complete (or your work day is over).

Well, oddly enough, this technique is nearly identical to the technique I have found for myself and used through college. I was using a proven time management technique without even knowing it!  After discovering the pomodoro technique, I decided to write some VBA code to create my very own timer.

The code file can be downloaded HERE. (Right-Click -> Save As)

The code is simple, I created a new module and 4 subs. First, I start with some global variables.


 Public iSets As Integer  
 Public iPomodoros As Integer  
 Public nextTime  


Note: These do not have to be public, that will depend on you. You could alternatively use static variables in your subroutines as well.

Then I create the four subs:

  1. start
  2. incrementSet
  3. incrementPoms
  4. Finish

The method I use to set off the timer is application.ontime. I set it to run 25 minutes after the user clicks the OK button on the messagebox. After 25 minutes, my incrementPoms routine is run. There the user is prompted to take a short or long break (depending on how many Pomodoros they have done).

Once the user is done, they simply run the "Finish" sub. This will stop the process and display how many Sets of 4 Pomodoros was completed along with the number of Pomodoros left over.

To run this macro, you can either type in the immediate window, use the Macro dialog box in Excel, or create your own fancy buttons which refer to each macro (One for start, the other for Finish).

That's it!



 '--------------------------------------------------  
 '--------------------------------------------------  
 'Pomodoro technique timer. Written by Lance in VBA  
 'use to increase your productivity.  
 '--------------------------------------------------  
 '--------------------------------------------------  
 '  
 '  
 '       Directions for use  
 '__________________________________________________  
 '1. Create a list of items you wish to complete  
 '2. Run the "start" subroutine  
 '3. Begin working on the first item and work on  
 '  that item exclusively until the timer is up  
 '4. When the timer finishes, take a break as  
 '  directed. Move on to another item on your  
 '  list. If you have not finished the work on  
 '  your current item, come back to it during  
 '  another pomodoro.  
 '5. When your list is complete, run the "Finish"  
 '  subroutine.  
 '6. Enjoy having completed your To Do list!  
 '__________________________________________________  
 Public iSets As Integer  
 Public iPomodoros As Integer  
 Public nextTime  
 Sub start()  
   'reset our variables  
   iPomodoros = 0  
   iSets = 0  
   'prepare the user  
   ans = MsgBox("Are you ready? Make sure you have your list of items!", vbYesNo + vbQuestion, _  
          "Ready?")  
   'if yes is clicked then  
   If ans = vbYes Then  
     'prepare, OK will start the timer  
     MsgBox "Your time will begin when you click OK!"  
     'set our next time value  
     nextTime = Now() + TimeValue("00:25:00")  
     'schedule our next pomodoro  
     Application.OnTime nextTime, "incrementPoms"  
   Else  
     'when the user clicks no  
     MsgBox "Okay, Come back when you are ready to begin"  
   End If  
 End Sub  
 Sub incrementSet()  
   'reset the pomodoros  
   iPomodoros = 0  
   'increment our sets  
   iSets = iSets + 1  
   'take our 15min. break  
   MsgBox "Take a 15-30min. Break. Then switch to a new task and click OK to start the timer again"  
 End Sub  
 Sub incrementPoms()  
   'increase the count  
   iPomodoros = iPomodoros + 1  
   'if we have a new set then make it  
   If iPomodoros = 4 Then  
     incrementSet  
   Else  
     'let us know we need a small break  
     MsgBox "Take a short break, 3-5minutes." & _  
         "Then switch to a new task and click OK to start the timer"  
   End If  
   'set our next time variable  
   nextTime = Now() + TimeValue("00:25:00")  
   'schedule the next pomodoro  
   Application.OnTime nextTime, "incrementPoms"  
 End Sub  
 Sub Finish()  
   'Let's see how well we did!  
   MsgBox "Congratulations! You completed " & iSets & " sets plus " & iPomodoros & " Pomodoros"  
   'cancel the next pomodoro  
   Application.OnTime nextTime, "incrementPoms", schedule:=False  
 End Sub  



No comments:

Post a Comment

VBA Add an animated Notification Box to your Excel Program

For those of us who create programs and add-ins in Excel, we are very, very familiar with the message box.  The message box gives us the opp...