Re: Debugging Help Please
Well I've worked around the problem by assigning the values outside of the new sub. However I'm still curious why those values didn't "Save". Does anyone have any idea why? Thanx.
Re: Debugging Help Please
Quote:
Originally Posted by SourSW
I've created a doubley linked list via classes. That whole list works fine. I can traverse it no problem. However, values I store in each node aren't saved/carried over. The following lines are where the problem is noticed:
1) list.lastNode = New clsNode(x, y)
2) list.firstNode = list.lastNode
and
1) currentNode = New clsNode(x, y, , list.firstNode)
2) list.firstNode.prevNode = currentNode
lets say y = 100 in line (1), when I execute the line (2), Y is still set to the default 0 for node. Why aren't the values kept? I've verified that the x and y values carry over to the clsNode::New sub. I know its probably something small i'm overlooking. I've tried using structures instead, but same problem occurs. Following is my stripped down code. Thanx.
Code:
Public Class clsNode
Public point As PointF
Public prevNode As clsNode
Public nextNode As clsNode
Public Sub New(ByVal x As Single, ByVal y As Single, Optional ByVal prev As clsNode = Nothing, Optional ByVal nxt As clsNode = Nothing)
Dim point As New PointF(x, y)
Me.prevNode = prev
Me.nextNode = nxt
End Sub
End Class
Public Class clsList
Public firstNode As clsNode = Nothing '//First node in entire list
Public lastNode As clsNode = Nothing '//Last node in entire list
End Class
Public Class frmCG
Public currentNode As clsNode '//Used to iterate through the list
Private testList As New clsList
Private Sub addValue(ByRef list As clsList, ByVal value As Single)
Dim x As Single = 0
Dim y As Single = 150 - value
If (list.firstNode Is Nothing) Then '//If list hasn't been started yet
list.lastNode = New clsNode(x, y)
list.firstNode = list.lastNode
Else '//Else push_front
currentNode = New clsNode(x, y, , list.firstNode)
list.firstNode.prevNode = currentNode
list.firstNode = currentNode
Do
currentNode = currentNode.nextNode
currentNode.point.X += 2
Loop Until (currentNode.nextNode Is Nothing)
End If
End Sub
End Class
Note testList is passed to sub AddValue from some other arbitruary sub.
if you observe closely, u passing the value of y = 100, in the contructor, but u are not assigning it to any attribute of the class, that's where the problem is.
Re: Debugging Help Please
I'm not sure what you mean. I use it when creating a new point. Shouldn't that be assigning it to the pointF variable?
Re: Debugging Help Please
Your problem is in the constructor
Code:
Public Class clsNode
Public point As PointF
Public prevNode As clsNode
Public nextNode As clsNode
Public Sub New(ByVal x As Single, ByVal y As Single, Optional ByVal prev As clsNode = Nothing, Optional ByVal nxt As clsNode = Nothing)
----> this is the problem Dim point As New PointF(x, y)
----> you're instancing a new point and declaring a new POINT variable and
you never assign it to me.point.
----> you can either do this
me.point = New pointF(x,y)
---->
or
dim point as new pointF(x,y)
me.point = point
Me.prevNode = prev
Me.nextNode = nxt
End Sub
End Class
Just like Ambreesh pointed out.
Re: Debugging Help Please
Oh. I had always assumed that it automatically assigned it with the new keyword. Thanx.