Quote Originally Posted by manavo11 View Post
The Dir way :

VB Code:
  1. 'Just add a listbox (List1)
  2.  
  3. Private Sub ListFiles(strPath As String, Optional Extention As String)
  4. 'Leave Extention blank for all files
  5.     Dim File As String
  6.    
  7.     If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
  8.    
  9.     If Trim$(Extention) = "" Then
  10.         Extention = "*.*"
  11.     ElseIf Left$(Extention, 2) <> "*." Then
  12.         Extention = "*." & Extention
  13.     End If
  14.    
  15.     File = Dir$(strPath & Extention)
  16.     Do While Len(File)
  17.         List1.AddItem File
  18.         File = Dir$
  19.     Loop
  20. End Sub
  21.  
  22. Private Sub Form_Load()
  23. ListFiles "C:\", "txt"
  24. End Sub
why do i get errors?
i added a list box named it List1

Error 1 Optional parameters must specify a default value. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 3 74 WindowsApplication1

Error 2 'Public ReadOnly Property Right() As Integer' has no parameters and its return type cannot be indexed. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 7 12 WindowsApplication1

Error 4 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 11 16 WindowsApplication1

Error 5 Type character '$' does not match declared data type 'Integer'. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 11 16 WindowsApplication1

Error 6 'AddItem' is not a member of 'System.Windows.Forms.ListBox'. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 17 13 WindowsApplication1