I'm building a list of names into a Listbox.
The names are in a string variable like this:
strNames = "name1,name2,name3,name4,"
I then split these names into an array:
Dim a() As String
a = Split(strNames, ",")
So,
a(0) = Name1
a(1) = Name2
a(2) = Name3
a(3) = Name4
a(4) = "" because there is a comma at end of strNames
Then I loop:
Everything OK. However, under certain circumstances it will be this way:
strNames = "name1,name2,name2,name3,"
I then split these names into an array:
Dim a() As String
a = Split(strNames, ",")
So,
a(0) = Name1
a(1) = Name2
a(2) = Name2
a(3) = Name3
a(4) = ""
Then I loop:
What is the best way to avoid getting Name2 in the lstNames listbox two times?
The names are in a string variable like this:
strNames = "name1,name2,name3,name4,"
I then split these names into an array:
Dim a() As String
a = Split(strNames, ",")
So,
a(0) = Name1
a(1) = Name2
a(2) = Name3
a(3) = Name4
a(4) = "" because there is a comma at end of strNames
Then I loop:
Code:
For n = 0 To UBound(a)
If a(n) = "" Then Exit For
lstNames.AddItem a(n)
Next n
strNames = "name1,name2,name2,name3,"
I then split these names into an array:
Dim a() As String
a = Split(strNames, ",")
So,
a(0) = Name1
a(1) = Name2
a(2) = Name2
a(3) = Name3
a(4) = ""
Then I loop:
Code:
For n = 0 To UBound(a)
If a(n) = "" Then Exit For
lstNames.AddItem a(n)
Next n