-
Separate this function?
Code:
Private Sub Form_Load()
MsgBox GetFiles("c:\")
End Sub
Function GetFiles(ByVal MyPath As String) As String
Dim sFiles As String
MyName = Dir(MyPath)
Do While MyName <> ""
Select Case UCase(Right(MyName, 3))
Case "TXT", "CSV", "CHM"
sFiles = sFiles & MyName & vbCr
Case Else
End Select
MyName = Dir() '
Loop
GetFiles = sFiles & vbCrLf
End Function
Right now if i msgbox Getfiles()then it msgboxs all the names under one msgbox instead of multiple msgboxs.
-
This should work!
Code:
Private Sub Form_Load()
Dim I As Long
Dim Files() As String
Files = Split(GetFiles("c:\"), vbCr)
For I = Lbound(Files) to UBound(Files) - 1
MsgBox Files(I)
Next I
Erase Files
End Sub
Function GetFiles(ByVal MyPath As String) As String
Dim sFiles As String
MyName = Dir(MyPath)
Do While MyName <> ""
Select Case UCase(Right(MyName, 3))
Case "TXT", "CSV", "CHM"
sFiles = sFiles & MyName & vbCr
End Select
MyName = Dir() '
Loop
GetFiles = sFiles & vbCrLf
End Function
-
instead of doing it like is there anyway to split it within the GetFiles() func?
-
Sure!
Code:
Private Sub Form_Load()
Dim I As Long
Dim Files() As String
Files = GetFiles("c:\")
For I = LBound(Files) To UBound(Files)
MsgBox Files(I)
Next I
Erase Files
End Sub
Function GetFiles(ByVal MyPath As String) As String()
Dim MyName As String
Dim Files() As String
Dim fc As Long
MyName = Dir(MyPath)
Do While MyName <> ""
Select Case UCase(Right(MyName, 3))
Case "TXT", "CSV", "CHM"
fc = fc + 1
ReDim Preserve Files(1 To fc)
Files(fc) = MyName
End Select
MyName = Dir()
Loop
GetFiles = Files()
Erase Files
End Function
-
 Originally Posted by WeightOver2001
it works alright when the path is just c:\.
but i get a subscript range error if i change it,
Files = GetFiles("c:\" + "Programming Files")
That is because you selected a folder that did not have any files that matched your criteria. Here is a version that looks for that:
Code:
Private Sub Form_Load()
Dim I As Long
Dim Files() As String
Files = GetFiles("c:\programming files")
For I = LBound(Files) To UBound(Files)
MsgBox Files(I)
Next I
Erase Files
End Sub
Function GetFiles(ByVal MyPath As String) As String()
Dim MyName As String
Dim Files() As String
Dim fc As Long
MyName = Dir(MyPath)
Do While MyName <> ""
Select Case UCase(Right(MyName, 3))
Case "TXT", "CSV", "CHM"
fc = fc + 1
ReDim Preserve Files(1 To fc)
Files(fc) = MyName
End Select
MyName = Dir()
Loop
If fc = 0 Then Files = Split("")
GetFiles = Files()
Erase Files
End Function
Similar Threads
-
By K. Soe in forum VB Classic
Replies: 8
Last Post: 03-08-2003, 06:25 PM
-
By Michael Shutt in forum VB Classic
Replies: 6
Last Post: 04-05-2001, 02:25 AM
-
By Patrick Comeau in forum VB Classic
Replies: 6
Last Post: 03-22-2001, 10:50 PM
-
By Julian Milano in forum VB Classic
Replies: 2
Last Post: 08-11-2000, 12:11 PM
-
By Kunal Sharma in forum VB Classic
Replies: 2
Last Post: 04-25-2000, 03:45 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks