Multiple Objects - Example 2
To avoid the messy naming problems, there is another approach to get multiple objects.
Starting with Event4.vbp, I added a Standard module with Sub Main, and set the Startup
object (under Project Properties) to be Sub Main. This asks you how many objects you want
via the InputBox function.
Then the program dynamically creates new instances of the
Form object. Then you can play with the multiple forms to see what happens. You should see
some "debug" messages appear in the Immediate Window when you run this.
What happens is that the code starts running in the Class object created by the Form
you clicked on. If you click on another Form's "GO" button, it interrupts what
was happening, and starts executing the code in the LongTask method of THAT Form's Class
The reason this happens is the DoEvents statements in the code. If you comment those
out, then the mouse clicks are queued up. The mouse clicks are not handled until the code
in the LongTask method finishes executing. DoEvents literally tells Windows to pause a
moment, and handle any pending user interface events. This can create some unexpected
results when code that is running is temporarily interrupted, and then resumes later.
If you look carefully at the messages that appear in the Immediate Window, it looks
like any interrupted code only executes once after it resumes. This is due to the actual
code in the LongTask method of the Class module.