Results 1 to 4 of 4

Thread: A very Hard Question!!!!!!!!!!!

  1. #1

    Thread Starter
    Hyperactive Member kourosh's Avatar
    Join Date
    Aug 1999
    Location
    Vancouver, British Columbia, Canada
    Posts
    256

    Post

    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.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Not so hard...
    here's what you'll need
    two text boxes[text1,text2]
    one timer[timer1]
    on image[image1]
    command button[command1]
    ---
    in the timer put:
    Code:
    image1.move text1 text2
    if image1.left + image1.width > form1.width then text1.text = int (90 * rnd + 1) * -1
    if image1.top + image1.height - 300 > form1.height then text2.text = int (90 * rnd + 1) * -1
    if image1.left < 0 then text1.text = int (90 * rnd + 1)
    if image1.top < 0 then text2.text = int (90 * rnd + 1)
    In the textboxes put a number or have an onload generate a random number for them but make them invisible
    in the command button put:
    Code:
    if timer1.enabled = true then
    timer1.enables = false
    else
    timer1.enables = true
    end if
    do whatever with the image
    the -300 may need to be changed depending the title bar because that's included with the height.
    set the interval of the timer to higher for a slower scroll lower for faster
    you might want to change the rnd statement to:
    (45 * rnd + 1) + 45
    this will set the speed for a faster update


    ------------------
    DiGiTaIErRoR

  3. #3

    Thread Starter
    Hyperactive Member kourosh's Avatar
    Join Date
    Aug 1999
    Location
    Vancouver, British Columbia, Canada
    Posts
    256

    Post

    Hi
    Thanks for your help, but I didn't understand the reason that you used the text box's??
    Maybe you didn't understand my question!! I have an image in the center of the form and I want the image to find a random direction and move. Whenever it hit one of the sides then change it direction. I don't think I be needing any text box though.

    ''''''''''''''''
    Kourosh Gonabadi
    VB Student
    ''''''''''''''''

    [This message has been edited by kourosh (edited 01-15-2000).]

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    textboxes tell it the direction to go

    ------------------
    DiGiTaIErRoR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width