Results 1 to 9 of 9

Thread: How to simplify these codes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    How to simplify these codes

    i need thelp to simplify these codes

    VB Code:
    1. FindStr = "*.mp3"
    2.     FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
    3.     TotalScan = TotalScan + NumFiles
    4.    
    5.     FindStr = "*.asf"
    6.     FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
    7.     TotalScan = TotalScan + NumFiles
    8.    
    9.     FindStr = "*.wma"
    10.     FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
    11.     TotalScan = TotalScan + NumFiles
    12.     '.... more extension

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    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:
    1. Open "C:\Files.txt" for input as #1
    2.  
    3. Do Until EOF(1)
    4.      Input #1, FindStr
    5.      FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
    6.      TotalScan = TotalScan + NumFiles
    7. Loop
    8.  
    9. Close #1

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to simplify these codes

    Alternatively you could make an array, and use a loop:
    VB Code:
    1. Dim varExtensions as Variant
    2. Dim lngLoopCount as Long
    3.     varExtensions = Array("*.mp3", "*.asf", "*.wma")  'add more as required
    4.  
    5.     For lngLoopCount = 0 To Ubound(varExtensions)
    6.       FileSize = FindFilesAPI(SearchPath, varExtensions(lngLoopCount), NumFiles, NumDirs)
    7.       TotalScan = TotalScan + NumFiles
    8.     Next lngLoopCount

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: How to simplify these codes

    that's what i'm looking for
    thanks

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: How to simplify these codes

    however i got this error
    byref argument type mismatch

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. FileSize = FindFilesAPI(SearchPath, [u]CStr([/u]varExtensions(lngLoopCount)[u])[/u], NumFiles, NumDirs)

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width