What about having one timer for motion and the other for doors. Each tick of the first timer would advance the elevator one unit in whatever direction it happens to be moving (unless the elevator is currently stationary). It would be a state-driven device with states suca as "stationary", "moving", "doors open", etc. A second timer could run when the doors are open and would determine when the doors should close.
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
How about something like this:
Create 9 buttons named btn1 - btn9. Stack them vertically and space them so that they are 50 y units apart centre to centre. Create a label and place it to the right of btn1. Create a timer for the elevator car and give it an interval of 50. Create a second timer for the door and give it an interval of 1000. You can start the door timer when the door opens. After 5 seconds you can close the door. As for the car timer, when the elevator is moving, on every "tick" of the timer you can adjust the Y position of the label by one. This way, the label will move up and down to indicate the location of the car. On every "tick" you can check if the label lines up with a floor button. If the floor button has been clicked you can stop at that floor (disable car timer, open door, enable door timer).
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
You could use one handler Sub for all of the buttons. That would save a lot of redundant code. For an example of how to do that see here
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
Also, instead of having a separate checkbox and button for each floor you could get rid of the checkbox and just use the buttons. When a button is clicked you could change the background colour from grey to yellow, then change it back from yellow to grey when the car stops at that floor. You wouldn't need the select statement in the button handler. You could just modify the properties of the button specified by "sender".
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159