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
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
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
Re: How to simplify these codes
that's what i'm looking for
thanks
Re: How to simplify these codes
however i got this error
byref argument type mismatch
Re: How to simplify these codes
Did you Dim all your variables?
Which line did you get the error in?
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)
Re: How to simplify these codes
Why is it even defined as a variant? Just curious.
Re: How to simplify these codes
It's a Variant because that is what the Array function returns. ;)