Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL
Expertise: Beginner
Mar 24, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

"Null" method

I want to be able to start a section of code if nothing is happening in an application. This type of 'null' method is useful for default tasks. How can I do this?

What is the sound of one hand clapping?

Part of this question is addressed fairly easily, and part of the question is a slippery slope. To implement a null method, you need to be able to find a way to account for time in your application, since you will want to determine how long to wait for something to happen, as well as a definition of what "nothing happening" means.

The first part of the question can be handled by using the TestCommand() method. The TestCommand() method is called many times a second (I think it's around 12 times a second) to test the status of menu items and push buttons in the tool bar. You can use this automatic function to implement an internal clock.

If you wanted to perform a particular action after the TestCommand() method had been executed 50 times, you would use code for the method that read like this:

STATIC nCount AS Integer
nCount = nCount + 1
IF nCount = 50 THEN
        nCount = 0

If you only wanted this code to execute if a certain condition were true, you could add a user-defined property, like udpTime, to the container which had TestCommand() method and modify the code to look like this:

udpTime = udpTime + 1
IF updTime = 50 THEN
        udpTime = 0

By setting a user defined property instead of an internal variable, you let other methods access the value, so that when something happened, the action could change the value of the udpTime property to 0.

The problem now becomes philosophical. The basic premise behind client/server applications is that the application reacts to a user's actions. All applications spend a lot of time waiting for something to happen, and how you can translate that into some type of discrete action or method. If, for instance, you define 'nothing happening' as no movement through a recordset, you could reset the udpTime property whenever you changed the row in the recordset. But if you want to define all keystrokes or mouse movements as something happening, you would have to add code to a number of methods to reset the property.

In a client/server application, the concept of 'nothing happening' is always subject to change since a user can make something happen at any time, so the idea of waiting until you have an empty space may be difficult to implement. But if you were to use the same techniques for a more discrete action, such as rolling back a transaction if it had not been committed in a certain time frame, you would have a much better chance of realizing a good result.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date