Animated Ball



'-----------------------------
' strongly typed
'-----------------------------

Option Explicit

'-----------------------------
' global variables declaration
'-----------------------------

Dim x As Integer
Dim y As Integer
Dim xCounter As Integer
Dim yCounter As Integer
Const conRadius = 5

Private Sub UserControl_Initialize()
    Let x = ScaleWidth \ 2
    Let y = ScaleHeight \ 2
    Let xCounter = 5
    Let yCounter = 5
End Sub

Private Sub cmdMove_Click()
    If cmdMove.Caption = "Go!" Then
       Timer1.Enabled = True
       cmdMove.Caption = "Stop!"
    Else
       Timer1.Enabled = False
       cmdMove.Caption = "Go!"
    End If
End Sub

Private Sub Timer1_Timer()

    DoEvents
    Cls
    If x + conRadius >= ScaleWidth Or _
       x - conRadius <= 0 Then
       Let xCounter = -xCounter
    End If
    If y + conRadius >= ScaleHeight Or _
       y - conRadius <= 0 Then
       Let yCounter = -yCounter
    End If
    
    Let x = x + xCounter
    Let y = y + yCounter
    
    Circle (x, y), conRadius, QBColor(4)
    
End Sub