19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

300 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

[Run <strong>and</strong> move the thumbs on the scroll bars.]<br />

In Example 5, when you drag the thumb, the face does not move until the dragging is<br />

completed. This can be corrected by adding the following two event procedures.<br />

Private Sub hsbXPos_Scroll() lblFace.Left = hsbXPos.ValueEnd SubPrivate Sub vsbY-<br />

Pos_Scroll() lblFace.Top = vsbYPos.ValueEnd Sub<br />

THE TIMER CONTROL<br />

The timer control, which is invisible during run time, triggers an event after a specified amount<br />

of time. The length of time, measured in milliseconds, is set with the Interval property to be<br />

any number from 0 to 65,535 (about 1 minute <strong>and</strong> 5 seconds). The event triggered each time<br />

Timer1.Interval milliseconds elapses is called Timer1_Timer( ). In order to begin timing, a timer<br />

must first be turned on by setting its Enabled property to True. A timer is turned off either by<br />

setting its Enabled property to False or by setting its Interval property to 0. The st<strong>and</strong>ard prefix<br />

for the name of a timer control is tmr.<br />

EXAMPLE 6<br />

The following program creates a stopwatch that updates the time every tenth of a second.<br />

Object Property Setting<br />

frmWatch Caption Stopwatch<br />

cmdStart Caption Start<br />

lblSeconds Caption Seconds<br />

lblTime Caption (blank)<br />

cmdStop Caption Stop<br />

tmrWatch Interval 100<br />

Enabled False<br />

Private Sub cmdStart_Click()<br />

lblTime.Caption = “ 0” ‘Reset watch<br />

tmrWatch.Enabled = True<br />

End Sub<br />

Private Sub cmdStop_Click()<br />

tmrWatch.Enabled = False<br />

End Sub<br />

Private Sub tmrWatch_Timer()<br />

lblTime.Caption = Str(Val(lblTime.Caption) + .1)<br />

End Sub<br />

[Run, click on the Start button, wait 10.8 seconds, <strong>and</strong> click on the Stop button.]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!