Hi, I want to move a shape (label) when I press WASD around a maze. I got what I have so far off the net, but I cant figure out whats wrong with it.

Public x 1 'This is whats wrong - it says "End of statement expected" when mouse over
Public y 1 'the "1"

Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
' if keypressed is right move the shape three more
' spaces to the right
If KeyCode = 68 Then
x = x + 3
shape1.Move(x, y)
End If
' if keypressed is left move the shape three more
' spaces to the left
If KeyCode = 65 Then
x = x - 3
shape1.Move(x, y)
End If

If KeyCode = 83 Then
y = y + 3
shape1.Move(x, y)
End If

If KeyCode = 86 Then
y = y - 3
shape1.Move(x, y)
End If
End Sub

Note Im completely new to this so keep it simple please!
Thanks!

Answered by Jx_Man 987 in a post from
Public x = 1 'This is whats wrong - it says "End of statement expected" when mouse over
Public y = 1 'the "1"
Answered by Unhnd_Exception 216 in a post from

Move isn't a method its an event.

Just set the location of the label

shape1.Location = new Point(x,y)

All 7 Replies

Public x = 1 'This is whats wrong - it says "End of statement expected" when mouse over
Public y = 1 'the "1"

When I do this,

shape1.Move

Is underlined in blue and I still can't run it Move isn't a method its an event.

Just set the location of the label

shape1.Location = new Point(x,y)

But then how do you not just set the location but make the location change depending on where the shape already is?

Im trying to make a shape move around the maze with WASD which seems to be harder than I thought it would be :s This will move the label around with the WASD keys or the Up,Left,Down, or Right arrow keys. From its current Position.

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.A, Keys.Left
shape1.Location += New Size(-3, 0)
Case Keys.D, Keys.Right
shape1.Location += New Size(3, 0)
Case Keys.W, Keys.Up
shape1.Location += New Size(0, -3)
Case Keys.S, Keys.Down
shape1.Location += New Size(0, 3)
End Select
End Sub

Ha ha! Thank you Exception :)

Would still appreciate if there was a way if for example if you pressed A+S then it would move diagonally down.

Case Keys.A And Keys.S 'also tried using "+" instead of "and"
shape1.Location += New Size(-3, 3)

Ha ha! Thank you Exception :)

Would still appreciate if there was a way if for example if you pressed A+S then it would move diagonally down.