Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21835

[RESOLVED] Avoiding duplicates

$
0
0
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:

Code:

For n = 0 To UBound(a)
  If a(n) = "" Then Exit For
  lstNames.AddItem a(n)
 Next n

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:

Code:

For n = 0 To UBound(a)
  If a(n) = "" Then Exit For
  lstNames.AddItem a(n)
 Next n

What is the best way to avoid getting Name2 in the lstNames listbox two times?

Viewing all articles
Browse latest Browse all 21835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>