This isn't the right place to discuss VB code... but POLLING is a methodology equally applicable to any code (including PBP) where you continually check (poll) an I/O port, or a Flag, or a Register, or your Bank Account, or whatever, for a change to happen.
This 'polling' is done in a loop. The loop can be a tight loop where you a looking for a change and acting on it immediately, or it can be a relatively loose loop, where you only check once in a while. The analogy here is if you're flat-broke, you check your bank account often so you can draw some cash out the instant your paycheck arrives. If you've ten-grand in the bank then you'll probably only check your bank account once a month when the statement falls through your letterbox. The frequency of polling (how often you do it over what length of time) is determined by your application (or desperation!). eg Capturing the picture of a bullet whizzing past your camera by polling a sensor on a port will require a far tighter loop than say polling for a push-button press on your toilet flush.
VB example...
Here is a boring and benign method of getting one character (an ASCII uppercase 'A') from the Keyboard...
KeyboardLoop:
A$=INPUT$(1)
If A$<>"A" then goto KeyboardLoop
Execution will stop at the above line until the user enters one character from the keyboard, only then will the program verify it's correct and proceed accordingly. This is NOT polling.
Now here...
KeyboardLoop:
A$=INKEY$
If A$<>"A" then goto KeyboardLoop
... we have the SAME RESULT, but this time using a 'polling' method. We are actually in an ACTIVE loop waiting for the event to happen. Execution is not suspended, but executes the loop continuously. Using the polling method, we can introduce other code into our active loop which will be executed whether the user presses the keyboard or goes off on holiday.
Melanie
Bookmarks