❓ Check if Value Exist in Listbox

Posts 1–3 of 3 · Page 1 of 1
❓ Check if Value Exist in Listbox
ok so I am having troubles with some of my code and would be nice if someone could help me out a little.

Here is what I am trying to do I want to be able to add a dll file (*.dll) using openfiledialog and get the file name of the file and add it to listbox. In the listbox I want it to say the name of all the added dlls files. But if the user adds a dll file and if it already exists in the list box then i dont want to add it. Only add it if it doesn't already exist.

Here is some of my code which might help out all little which I have so far but is not working of course.

LbDll = Listbox

Code:
'Show the OpenFile Dialog.
DllPath As String
With OpenFileDialog1
.FileName = ""
'If user pressed OK then continue...
If .ShowDialog = Windows.Forms.DialogResult.OK Then
DllPath = .FileName.Substring(.FileName.LastIndexOf("\"))
Dim DllFileName As String = DllPath.Replace("\", "")

For Each i In LbDll.Items
If i.Contains(DllFileName) Then
MsgBox("A Dll with the same Name already Exists!")
Else
MsgBox("Dll does not exist")
End If
Else
'Didn't select a file.
End If
End With
Code:
'Show the OpenFile Dialog.
With OpenFileDialog1
	.FileName = ""
	'If user pressed OK then continue...
	If .ShowDialog = Windows.Forms.DialogResult.OK Then
		DllFileName = IO.Path.GetFileName(.FileName)

		If LbDll.Items.Contains(DllFileName)
			MsgBox("A Dll with the same Name already Exists!")
		Else
			MsgBox("Dll does not exist")
		End If
	Else
		'Didn't select a file.
	End If
End With
Quote Originally Posted by master131 View Post
Code:
'Show the OpenFile Dialog.
With OpenFileDialog1
	.FileName = ""
	'If user pressed OK then continue...
	If .ShowDialog = Windows.Forms.DialogResult.OK Then
		DllFileName = IO.Path.GetFileName(.FileName)

		If LbDll.Items.Contains(DllFileName)
			MsgBox("A Dll with the same Name already Exists!")
		Else
			MsgBox("Dll does not exist")
		End If
	Else
		'Didn't select a file.
	End If
End With
Thank you soo much! You saved the day!
/solved
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us