Req help with Arraylist and structure not getting values back in vb.net TIA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having trouble with this code...It won't loop though each value any one know why?
TIA

Public Class TestData
Public Structure Element
Dim eName As String
Dim eN1 As String
Dim eN2 As String
End Structure

End Class



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim p As New TestData.Element
Dim aList As New ArrayList

'ComboBox1.Items.Add("test")
p.eName = "000"
p.eN1 = "000 field1"
p.eN2 = "000 field2"
aList.Add(p)
p = Nothing
p.eName = "818"
p.eN1 = "818 field1"
p.eN2 = "818 field2"
aList.Add(p)
p = Nothing
p.eName = "616"
p.eN1 = "616 field1"
p.eN2 = "616 field2"
aList.Add(p)
p = Nothing
Dim i As Integer

For i = 0 To aList.Count - 1

'ComboBox1.Items.Add(p.eName)
Debug.WriteLine(String.Format( _
"alist holds {0} ele.", aList(i)))


Next

End Sub
 
I'm having trouble with this code...It won't loop though each value any
one know why?
TIA

Public Class TestData
Public Structure Element
Dim eName As String
Dim eN1 As String
Dim eN2 As String
End Structure

End Class



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim p As New TestData.Element
Dim aList As New ArrayList

'ComboBox1.Items.Add("test")
p.eName = "000"
p.eN1 = "000 field1"
p.eN2 = "000 field2"
aList.Add(p)
p = Nothing
p.eName = "818"
p.eN1 = "818 field1"
p.eN2 = "818 field2"
aList.Add(p)
p = Nothing
p.eName = "616"
p.eN1 = "616 field1"
p.eN2 = "616 field2"
aList.Add(p)
p = Nothing
Dim i As Integer

For i = 0 To aList.Count - 1

'ComboBox1.Items.Add(p.eName)
Debug.WriteLine(String.Format( _
"alist holds {0} ele.", aList(i)))


Next

End Sub

I am not sure exactly what you mean by not being able to loop through each
value. If you want to load your combo box with p.eName you can access it
like the following example.

Debug.WriteLine(String.Format("alist holds {0} ele.", CType(aList(i),
TestData.Element).eName))



Try that instead inside of your for loop. If I am missing something let
me know. I might not have understood what the problem is.

jjardine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top