Checking for the text files in the list box

  • Thread starter Thread starter Flying Whiz
  • Start date Start date
F

Flying Whiz

I am trying to show a message when there are no Text files in the List
box.But every time it is showing me the message even if there are text
files in the listbox.How can I do this.

This is the code I am trying to use.

Dim StrFiles() As String
Dim StrFile As String

StrFiles = System.IO.Directory.GetFiles("\Program Files\Dev_Tool\",
"*.txt")

If StrFile = "" Then
MsgBox("Copy the 'txt' file in '\Program Files\Dev_Tool\'
folder and then run the application again", vbOKOnly, "Error Message")
Application.Exit()
Else

For Each StrFile In StrFiles
ListBox1.Items.Add(System.IO.Path.GetFileName(StrFile))
Next

End If


Thanks
Whiz
 
Try doing a check on the "StrFiles" Length to see if there were any items
returned.

If StrFiles.Length = 0 Then
 
Back
Top