PDA

View Full Version : vb HARD question (not working)



Demonicman
06-20-2008, 02:38 PM
Public Class Form2

Dim X As Integer
Dim Y As Integer
Dim P As Integer = 3
Dim Key As Integer = 1
Dim Pic As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy1.bmp")
Dim Pic2 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy2.bmp")
Dim Pic3 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy3.bmp")
Dim Pic4 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy4.bmp")
Dim Pic5 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy5.bmp")
Dim Pic6 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy6.bmp")
Dim Pic7 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy7.bmp")
Dim Pic8 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy8.bmp")
Dim Pic9 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy9.bmp")
Dim Pic10 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy10.bmp")
Dim Pic11 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy11.bmp")
Dim Pic12 As Image = New Bitmap("C:\Documents and Settings\1093480\My Documents\My Pictures\guy12.bmp")


Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
X = Guy.Left
Y = Guy.Top

Dim Xloc As Integer
Dim Yloc As Integer
Xloc = Guy.Location.X
Yloc = Guy.Location.Y

Label2.Text = Xloc & ", " & Yloc

If e.KeyValue = Keys.Up Then
If Key <> 1 Then
P = 1
End If
Key = 1
If Y < 20 Then

ElseIf P = 1 Then
Guy.Image = Pic7
Guy.Location = New Point(X, Y - 10)
P = 2
ElseIf P = 2 Then
Guy.Image = Pic8
Guy.Location = New Point(X, Y - 10)
P = 3
ElseIf P = 3 Then
Guy.Image = Pic7
Guy.Location = New Point(X, Y - 10)
P = 4
ElseIf P = 4 Then
Guy.Image = Pic8
Guy.Location = New Point(X, Y - 10)
P = 1
End If

End If

If e.KeyValue = Keys.Down Then
If Key <> 2 Then
P = 1
End If
Key = 2
If Y > 600 Then

ElseIf P = 1 Then
Guy.Image = Pic
Guy.Location = New Point(X, Y + 10)
P = 2
ElseIf P = 2 Then
Guy.Image = Pic2
Guy.Location = New Point(X, Y + 10)
P = 3
ElseIf P = 3 Then
Guy.Image = Pic
Guy.Location = New Point(X, Y + 10)
P = 4
ElseIf P = 4 Then
Guy.Image = Pic2
Guy.Location = New Point(X, Y + 10)
P = 1
End If
End If

If e.KeyValue = Keys.Left Then
If Key <> 4 Then
P = 1
End If
Key = 4
If X < 20 Then

ElseIf P = 1 Then
Guy.Image = Pic3
Guy.Location = New Point(X - 10, Y)
P = 2
ElseIf P = 2 Then
Guy.Image = Pic9
Guy.Location = New Point(X - 10, Y)
P = 3
ElseIf P = 3 Then
Guy.Image = Pic4
Guy.Location = New Point(X - 10, Y)
P = 4
ElseIf P = 4 Then
Guy.Image = Pic9
Guy.Location = New Point(X - 10, Y)
P = 1
End If

End If

If e.KeyValue = Keys.Right Then
If Key <> 3 Then
P = 1
End If
Key = 3
If X > 745 Then

ElseIf P = 1 Then
Guy.Image = Pic5
Guy.Location = New Point(X + 10, Y)
P = 2
ElseIf P = 2 Then
Guy.Image = Pic10
Guy.Location = New Point(X + 10, Y)
P = 3
ElseIf P = 3 Then
Guy.Image = Pic6
Guy.Location = New Point(X + 10, Y)
P = 4
ElseIf P = 4 Then
Guy.Image = Pic10
Guy.Location = New Point(X + 10, Y)
P = 1
End If

End If

End Sub

End Class

This is my code used to move the label around. It works well on one project but on any other project it just does not work. Can someone tell me why this wouldnt work, or an alternate method to key presses?