If I want to have an array of strings that I can add to. How can I do this without keeping track of every time I add a new string.
So what I have been doing is this...
Dim myStrings(1000) As String
Dim myStringCount As Integer
Then while the program is doing its sorting work
If Not myStrings.Contains(pair.Primary) Then
myStrings(myStringCount) = pair.Primary
myStringCount = myStringCount + 1
End If
Then when I display them
I do a for loop using myStringCount to display each item
For i = 0 To myStringCount - 1
ListBox1.Items.Add(MyStrings(i))
Next
I'm sure there is a more efficient way. How would you guys do this?
Visual Basic.NET
Last Comment
Neil Fleming
8/22/2022 - Mon
Jayadev Nair
Are you looking for -
For Each item As String In myStrings ListBox1.Items.Add(item)Next
The end goal is to use the items in the list to create a check boxes at run time that can be selected to show the data from that pair. Would you still do it with the single csv string?
I think it depends partly on how many items there are going to be in your list. If it's <30 I'd use the single csv string approach because then you have no need to track how many items there are.
If it's a very large number it may be better to reDim Preserve the array as you go along. I guess you are creating checkboxes on the fly, in which case you will need to iterate the array as in your original example.
Open in new window