VB Code:
Dim pic2 As PictureBox pic2 = snake.Item(0) If pic2.Location.Y = picFood.Location.Y Then 'move food to new location RandomFoodLocation() 'add length to snake snake.Add(New PictureBox().Location = New Point(pic2.Location.X, pic2.Location.Y + (growth + 17))) growth += 17 End If
The pic2 = snake.item(0) is causing problems. The compiler says that snake.item(0) is returning a boolean value of false. But it the item(0) should be a picturebox.
I thought I forgot to add the first ball to the arraylist, but I checked and it gets added on form_load sub procedure.
VB Code:
Private Sub frmSnakeGame_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load snake.Add(picBall) RandomFoodLocation() End Sub
Code:InvalidCastException was unhandled Unable to cast object of type "System.Boolean' to type 'System.Windows.Forms.PictureBox'.




Reply With Quote