Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Declaring Variables - Help needed please

sheepssheeps Posts: 6Member
Ive just started programming and am not sure why this wont work!!
Is it because i havent declared the variables??
Can someone help please.
Nick




Dim direction As String


Private Sub Command1_Click()
direction = "up"
End Sub

Private Sub Command2_Click()
direction = "down"
End Sub

Private Sub Command3_Click()
direction = "left"
End Sub

Private Sub Command4_Click()
direction = "right"
End Sub

Private Sub Command5_Click()
Menu.Show
Unload Me
End Sub

Private Sub Form_Load()
direction = "still"
End Sub

Private Sub Timer1_Timer()

Select Case direction
Case "up"
Shape2.Top = Shape2.Top - 20
Case "down"
Shape2.Top = Shape2.Top + 20
Case "right"
Shape2.Left = Shape2.Left + 20
Case "left"
Shape2.Left = Shape2.Left - 20
End Select

For i = 0 To 9
If Shape2.Top + Shape2.Height > Shape1(i).Top And Shape2.Top < Shape1(i).Top + Shape(i).Height And Shape2.Left + Shape2.Width > Shape1(i).Left And Shape2.Left < Shape1(i).Left + Shape1(i).Width Then
MsgBox "HIT"
Shape2.Top = 240
Shape2.Left = 120
direction = "still"
End If
If Shape2.Top + Shape2.Height > Shape3.Top And Shape2.Top < Shape3.Top + Shape3.Height And Shape2.Left + Shape2.Width > Shape3.Left And Shape2.Left < Shape3.Left + Shape3.Width Then
MsgBox "Made It"
Shape2.Top = 240
Shape2.Left = 120
direction = "still"
End If
Next i
End Sub

Comments

  • GazzaladGazzalad Posts: 85Member
    In your last bit of code you have:

    For i = 0 To 9
    If Shape2.Top + Shape2.Height > Shape1(i).Top And Shape2.Top < Shape1(i).Top + Shape(i).Height And Shape2.Left + Shape2.Width > Shape1(i).Left And Shape2.Left < Shape1(i).Left + Shape1(i).Width Then

    In there you have Shape(i), but I can not see that used anywhere else. Should it be Shape1(i) or Shape2(i)???

    G
Sign In or Register to comment.