kourosh
Jan 14th, 2000, 12:08 PM
Hi, I am doing a project for my school and our teacher ask me to creat an application which contain an image and when I press a button image start moving and when the image hit the walls change it direction randomly, I have created the codes but when every I run it my application crashes. Please help me if you know what is wrong with these codes.
CODES
=======
Private Sub cmdstart_Click()
Dim Random As Integer
Dim Direction As Integer
If imgmove.Left = 0 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 3)
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
Else
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop Until (imgmove.Top = 4140)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
End If
End If
End If
Else
If imgmove.Top = 0 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 1)
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop Until (imgmove.Top = 4140)
Else
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop While (imgmove.Left = 0)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
End If
End If
End If
Else
If imgmove.Top = 4140 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 2)
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop Until (imgmove.Left = 0)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
Else
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
End If
End If
End If
Else
If imgmove.Left = 6900 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 4)
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
Else
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop While (imgmove.Top = 4140)
Else
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop While (imgmove.Left = 0)
Else
MsgBox "Unable to comply", vbInformation + vbOKOnly, "Error"
End If
End If
End If
End If
End If
End If
End If
End Sub
=============================
Code Ended
=============================
Thanks alot for your help.
CODES
=======
Private Sub cmdstart_Click()
Dim Random As Integer
Dim Direction As Integer
If imgmove.Left = 0 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 3)
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
Else
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop Until (imgmove.Top = 4140)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
End If
End If
End If
Else
If imgmove.Top = 0 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 1)
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop Until (imgmove.Top = 4140)
Else
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop While (imgmove.Left = 0)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
End If
End If
End If
Else
If imgmove.Top = 4140 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 2)
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop Until (imgmove.Left = 0)
Else
If Random = 4 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) + Val(Direction))
Loop Until (imgmove.Left = 6900)
Else
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
End If
End If
End If
Else
If imgmove.Left = 6900 Then
Do
Random = Int((4 - 1) * Rnd + 1)
Loop While (Random <> 4)
If Random = 1 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) - Val(Direction))
Loop Until (imgmove.Top = 0)
Else
If Random = 2 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Top = (Val(imgmove.Top) + Val(Direction))
Loop While (imgmove.Top = 4140)
Else
If Random = 3 Then
Do
Direction = Int((5 - 1) * Rnd + 1)
imgmove.Left = (Val(imgmove.Left) - Val(Direction))
Loop While (imgmove.Left = 0)
Else
MsgBox "Unable to comply", vbInformation + vbOKOnly, "Error"
End If
End If
End If
End If
End If
End If
End If
End Sub
=============================
Code Ended
=============================
Thanks alot for your help.