4 Replies - 1797 Views - Last Post: 05 June 2011 - 07:30 PM Rate Topic: -----

#1 Tyler_911  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 28
  • Joined: 01-June 07

[VB.NET] Variable is "Nothing" (Snake Game)

Posted 04 June 2011 - 07:34 PM

frmSnake.vb
Public Class frmSnake
    Public Snake As New clsSnake

    Private Sub frmSnake_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Snake.View = "Left"
        Snake.SpawnFirstNode()
        Snake.AddNewNode()
    End Sub

    Private Sub tmrMigrateNodes_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrMigrateNodes.Tick
        If Snake.View = "Left" Then
            Dim I As Integer
            For I = 0 To Snake.LastNodeTail
                If I = 0 Then
                    Snake.NodeCoords(I).LastX = Snake.Node(I).Location.X'This sets off an error
                    Snake.NodeCoords(I).LastY = Snake.Node(I).Location.Y
                    Snake.Node(I).Location = New Point(Snake.Node(I).Location.X - 20, Snake.Node(I).Location.Y)
                Else
                    Snake.NodeCoords(I).LastX = Snake.Node(I).Location.X
                    Snake.NodeCoords(I).LastY = Snake.Node(I).Location.Y
                    Snake.Node(I).Location = New Point(Snake.NodeCoords(I - 1).LastX, Snake.NodeCoords(I - 1).LastY)
                End If
            Next
        Else
        End If
    End Sub
End Class



clsSnake.vb
Public Class clsSnake
    Public Node(0 To 30) As Button
    Public NodeCoords(0 To 30) As clsCoords 'This is what we are looking at
    Public LastNodeTail As Integer
    Public View As String

    Public Sub AddNewNode()
        ReDim Preserve Node(LastNodeTail + 1)
        ReDim Preserve NodeCoords(LastNodeTail + 1)'This is not working
'How would I redim the object to the clsCoords class while preserving the objects data?
        Node(LastNodeTail + 1) = New Button

        Node(LastNodeTail + 1).Location = New Point(30 * Node(LastNodeTail).Location.X, 5 * Node(LastNodeTail).Location.Y)
        Node(LastNodeTail + 1).Visible = True
        Node(LastNodeTail + 1).Width = 10
        Node(LastNodeTail + 1).Height = 15
        Node(LastNodeTail + 1).Enabled = True
        frmSnake.Controls.Add(Node(LastNodeTail + 1))
        LastNodeTail = LastNodeTail + 1
    End Sub

    Public Sub SpawnFirstNode()
        ReDim Node(0)
        ReDim NodeCoords(0)
        LastNodeTail = 0
        Node(0) = New Button
        Node(0).Location = New Point(200, 200)
        Node(0).Visible = True
        Node(0).Width = 10
        Node(0).Height = 15
        Node(0).Enabled = True
        frmSnake.Controls.Add(Node(0))
    End Sub
End Class



clsCoords.vb
Public Class clsCoords
    Public CurrentX As Integer
    Public CurrentY As Integer
    Public LastX As Integer
    Public LastY As Integer
End Class



The problem is I need to preserve all previous coordinates so I ReDim Preserve but I need to do it to the Class. And I try this and the NodeCoords variable is set as "nothing" when i am debugging realtime. If you need any more information where you can help me it would be great, Thanks in advance ;)

This post has been edited by Tyler_911: 04 June 2011 - 07:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [VB.NET] Variable is "Nothing" (Snake Game)

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,142
  • Joined: 02-July 08

Re: [VB.NET] Variable is "Nothing" (Snake Game)

Posted 04 June 2011 - 08:55 PM

How about a List (Of T) for the buttons, that would be easier the ReDim an array.
Was This Post Helpful? 0
  • +
  • -

#3 Tyler_911  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 28
  • Joined: 01-June 07

Re: [VB.NET] Variable is "Nothing" (Snake Game)

Posted 05 June 2011 - 06:53 PM

View Posthawkvalley1, on 04 June 2011 - 09:55 PM, said:

How about a List (Of T) for the buttons, that would be easier the ReDim an array.

You didn't even read what I posted but thanks anyways...
Was This Post Helpful? -2
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,142
  • Joined: 02-July 08

Re: [VB.NET] Variable is "Nothing" (Snake Game)

Posted 05 June 2011 - 07:18 PM

When someone offers help, you don't have to show your ass. :withstupid:

What you don't realize - it would have helped ya!

This post has been edited by hawkvalley1: 05 June 2011 - 07:21 PM

Was This Post Helpful? 0
  • +
  • -

#5 Tyler_911  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 28
  • Joined: 01-June 07

Re: [VB.NET] Variable is "Nothing" (Snake Game)

Posted 05 June 2011 - 07:30 PM

View Posthawkvalley1, on 05 June 2011 - 08:18 PM, said:

When someone offers help, you don't have to show your ass. :withstupid:

What you don't realize - it would have helped ya!

My question wasn't relevent to what you posted and I already knew the other ways.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1