If you want, try this approach. It's a little more digestible for what you want.
VB Code:
Public Class Node Public Data As String Public NextP As Node End Class Private myNodes As Generic.List(Of Node) Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load myNodes = New Generic.List(Of Node) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim newNode As New Node If myNodes.Count > 0 Then myNodes(myNodes.Count - 1).NextP = newNode End If newNode.Data = GetData() myNodes.Add(newNode) End Sub
To test, use the following:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim display As New System.Text.StringBuilder For Each hold As Node In myNodes If hold.NextP IsNot Nothing Then 'LastOn won't have a reference to append. display.AppendLine(hold.Data & " ref: " & hold.NextP.Data) Else display.AppendLine(hold.Data & " ref: N/A") End If Next MessageBox.Show(display.ToString) End Sub
The difference is the code above will help you keep track of your order by using a collection. When a new item is added, the previous item's "NextP" is assigned to it.




Reply With Quote