' Ch. 8 Demo Program #6
' Mr. Minich
' This demo program illustrates the use of animation with an object's
'   Move method. It also illustrates the use of Timer, Shape, & Horizontal
'   Scrollbar controls.

Option Explicit
Dim mMoveAmount As Integer          ' the amount of rightward movement of the
                                    '   square each time the tmrHorizontal acts

Private Sub Form_Load()
    tmrHorizontal.Interval = 100    ' 1 tenth of a second
    tmrVertical.Interval = 1000     ' 1 full second
    tmrHorizontal.Enabled = False   ' square begins at rest
    tmrVertical.Enabled = False
    mMoveAmount = 100               ' an average speed for the beginner
End Sub

Private Sub cmdStartStop_Click()
    ' turns the timers off or on
    
    tmrVertical.Enabled = Not tmrVertical.Enabled
    tmrHorizontal.Enabled = Not tmrHorizontal.Enabled
    ' the Not operator changes the Enabled property from True to False and vice versa
    
    lblPosition = Abs(linLeft.X1 - shpSquare.Left) ' computing user's score
End Sub

Private Sub hsbSpeed_Change()       ' the speed of the square
    mMoveAmount = hsbSpeed.Value    '  is the same as the value of
End Sub                             '  the horiz. scroll bar
                                    
Private Sub tmrHorizontal_Timer()
    If (shpSquare.Left + shpSquare.Width) > Form1.Width Then
        shpSquare.Left = Form1.Left
    End If                          ' right edge detection
    
    shpSquare.Left = shpSquare.Left + mMoveAmount
End Sub

Private Sub tmrVertical_Timer()
    ' The label moves up and down at random
    
    shpSquare.Top = Int(Rnd * Form1.Height)
End Sub