|
-
Jun 22nd, 2006, 10:10 AM
#1
Thread Starter
Addicted Member
How to simplify these codes
i need thelp to simplify these codes
VB Code:
FindStr = "*.mp3"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
TotalScan = TotalScan + NumFiles
FindStr = "*.asf"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
TotalScan = TotalScan + NumFiles
FindStr = "*.wma"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
TotalScan = TotalScan + NumFiles
'.... more extension
-
Jun 22nd, 2006, 10:20 AM
#2
Frenzied Member
Re: How to simplify these codes
If you have a list of the file names you could probably put them in a text file and loop through the file and search every loop...
VB Code:
Open "C:\Files.txt" for input as #1
Do Until EOF(1)
Input #1, FindStr
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
TotalScan = TotalScan + NumFiles
Loop
Close #1
-
Jun 22nd, 2006, 10:42 AM
#3
Re: How to simplify these codes
Alternatively you could make an array, and use a loop:
VB Code:
Dim varExtensions as Variant
Dim lngLoopCount as Long
varExtensions = Array("*.mp3", "*.asf", "*.wma") 'add more as required
For lngLoopCount = 0 To Ubound(varExtensions)
FileSize = FindFilesAPI(SearchPath, varExtensions(lngLoopCount), NumFiles, NumDirs)
TotalScan = TotalScan + NumFiles
Next lngLoopCount
-
Jun 22nd, 2006, 01:01 PM
#4
Thread Starter
Addicted Member
Re: How to simplify these codes
that's what i'm looking for
thanks
-
Jun 22nd, 2006, 01:08 PM
#5
Thread Starter
Addicted Member
Re: How to simplify these codes
however i got this error
byref argument type mismatch
-
Jun 22nd, 2006, 01:25 PM
#6
Re: How to simplify these codes
Did you Dim all your variables?
Which line did you get the error in?
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 22nd, 2006, 01:31 PM
#7
Re: How to simplify these codes
I think that would be my fault.. I didn't convert the variant to a string for the API:
VB Code:
FileSize = FindFilesAPI(SearchPath, [u]CStr([/u]varExtensions(lngLoopCount)[u])[/u], NumFiles, NumDirs)
-
Jun 22nd, 2006, 02:26 PM
#8
Re: How to simplify these codes
Why is it even defined as a variant? Just curious.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 22nd, 2006, 04:23 PM
#9
Re: How to simplify these codes
It's a Variant because that is what the Array function returns.
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
|
Click Here to Expand Forum to Full Width
|