Add only one copy to a listbox?

02-16-2005, 04:32 PM
Hi, I'm making a simple program to show the files within a directory by specifing a directory and a wildcard such as *.txt*

It works fine for the part where it lists the files in the list box, but I would like it to only add one copy of the file to the listbox.

I was thinking something like a loop to compare the variable for the file which is strFile to the List1.List(i) or something like that.

Here is the file below, maybe you can get better insight from looking at what I'm trying to do.

02-16-2005, 06:58 PM
You can create a procedure that will validate the text you want to add. Something like this.

Dim i As Integer
If List1.ListCount = 0 Then
List1.AddItem Text1.Text
Exit Sub
End If
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
If Not List1.Text = Text1.Text Then
List1.AddItem Text1.Text
Exit For
End If
Next i

02-17-2005, 04:58 PM
Thanks, but your code does not work because of the fact that List1.Text or List1.List(i) will not always be = to strFile

At least I thinks thats why

I need a way to compare the variable strFile to All the List1 Listcontents and if no matches of the same item are found then strFile is added.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum