this is my code for the program
Dim b As Boolean
Dim b2 As Boolean
Private Sub Command1_Click()
If Command1.Caption = “Stop” Then
Command1.Caption = “Start”
Else
Command1.Caption = “Stop”
End If
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
b = True
b2 = True
End Sub
Private Sub Timer1_Timer()
If b2 = True Then
If b = True Then
Shape1.Left = Shape1.Left + 50
Shape1.Top = Shape1.Top + 75
End If
If Shape1.Top >= 3485 Then b = False
If b = False Then
Shape1.Left = Shape1.Left + 50
Shape1.Top = Shape1.Top – 75
End If
If Shape1.Top <= 0 Then b = True
End If
If Shape1.Left >= 9840 Then b2 = False
If b2 = False Then
If b = True Then
Shape1.Left = Shape1.Left – 50
Shape1.Top = Shape1.Top + 75
End If
If Shape1.Top >= 3485 Then b = False
If b = False Then
Shape1.Left = Shape1.Left – 50
Shape1.Top = Shape1.Top – 75
End If
If Shape1.Top <= 0 Then b = True
End If
If Shape1.Left <= 0 Then b2 = True
End Sub
1 Answer
? Favorite Answer
T have edited your code below. This assumes you have set the shape fillstyle to opaque in the shape1 property box.
Private Sub Command1_Click()
If Command1.Caption = “Stop” Then
Command1.Caption = “Start”
Else
Command1.Caption = “Stop”
End If
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
b = True
b2 = True
End Sub
Private Sub Timer1_Timer()
If b2 = True Then
If b = True Then
Shape1.Left = Shape1.Left + 50
Shape1.Top = Shape1.Top + 75
End If
If Shape1.Top >= 3485 Then
Shape1.FillColor = vbRed
b = False
End if
If b = False Then
Shape1.Left = Shape1.Left + 50
Shape1.Top = Shape1.Top – 75
End If
If Shape1.Top <= 0 Then
Shape1.FillColor = vbBlue
b = True
End If
If Shape1.Left >= 9840 Then
Shape1.FillColor = vbYellow
b2 = False
End If
If b2 = False Then
If b = True Then
Shape1.Left = Shape1.Left – 50
Shape1.Top = Shape1.Top + 75
End If
If Shape1.Top >= 3485 Then
Shape1.FillColor = vbGreen
b = False
End If
If b = False Then
Shape1.Left = Shape1.Left – 50
Shape1.Top = Shape1.Top – 75
End If
If Shape1.Top <= 0 Then b = True
End If
If Shape1.Left <= 0 Then b2 = True
End Sub