Monday, 9 April 2012

Do Events - Visual Basic for Applications

This was one of my first learnings in test automation. It is around 3 years back when I started to learn test automation technique that I came across this method called 'Do Events'.

At that time, I was trying to write keyword driven framework for the tool 'eTester', which has a scripting language of 'Visual Basic for Application' (VBA). During the framework development, there was a requirement for for loop and I wrote the code for it.

Code was written in such a way that it would click my application's button and would get in to the for loop and then would perform some action in the screen resulting because of the click performed previously.

Strangely, when I executed this code - I found that my application did not proceed further after clicking on the button. But the code worked perfectly fine when I ran the same code in 'Debug' mode.

I was wondering what could be the reason and was going over the internet search engines to discover the root cause. Unfortunately, I could not find what is the exact cause. Then I discovered that the root cause of the issue is the loop function that I had written in VBA.

I came to know that VBA has a peculiar behavior of hogging the system resources big time whenever it executes For statements/While loops. VBA would not free the resources to the events present in OS message queues until the loop is complete.

To allow the processor to executing the pending events in parallel with the loop statements, VBA requires 'Do Events' statement to be placed within the loops.

You can find more about 'Do Events' definition and usage in the below links:

Please let me know if you have any further queries on this.

No comments:

Post a Comment