Results 1 to 4 of 4

Thread: [RESOLVED] Overflow Error?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Resolved [RESOLVED] Overflow Error?

    heuy guys I am using findfilefirst code but I get an overflow error when I do.

    Here is the code.
    VB Code:
    1. Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
    2.     'KPD-Team 1999
    3.     'E-Mail: [email][email protected][/email]
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.    
    6.     Screen.MousePointer = vbHourglass
    7.    
    8.     Dim fileName As String ' Walking filename variable...
    9.     Dim DirName As String ' SubDirectory Name
    10.     Dim dirNames() As String ' Buffer for directory name entries
    11.     Dim nDir As Integer ' Number of directories in this path
    12.     Dim i As Integer ' For-loop counter...
    13.     Dim hSearch As Long ' Search Handle
    14.     Dim WFD As WIN32_FIND_DATA
    15.     Dim Cont As Integer
    16.     If Right(path, 1) <> "\" Then path = path & "\"
    17.     ' Search for subdirectories.
    18.     nDir = 0
    19.     ReDim dirNames(nDir)
    20.     Cont = True
    21.     hSearch = FindFirstFile(path & "*", WFD)
    22.     If hSearch <> INVALID_HANDLE_VALUE Then
    23.         Do While Cont
    24.         DoEvents
    25.         DirName = StripNulls(WFD.cFileName)
    26.         ' Ignore the current and encompassing directories.
    27.         If (DirName <> ".") And (DirName <> "..") Then
    28.             ' Check for directory with bitwise comparison.
    29.             If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
    30.                 dirNames(nDir) = DirName
    31.                 DirCount = DirCount + 1
    32.                 nDir = nDir + 1
    33.                 ReDim Preserve dirNames(nDir)
    34.             End If
    35.         End If
    36.         Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
    37.         Loop
    38.         Cont = FindClose(hSearch)
    39.     End If
    40.     ' Walk through this directory and sum file sizes.
    41.     hSearch = FindFirstFile(path & SearchStr, WFD)
    42.     Cont = True
    43.     If hSearch <> INVALID_HANDLE_VALUE Then
    44.         While Cont
    45.             DoEvents
    46.             fileName = StripNulls(WFD.cFileName)
    47.             If (fileName <> ".") And (fileName <> "..") Then
    48.                 FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
    49.                 FileCount = FileCount + 1
    50.                 List1.AddItem path & fileName
    51.                 Dim ixi As Long
    52.  
    53. For ixi = 0 To List1.ListCount - 1
    54.  
    55.      
    56.  
    57.     If InStr(1, UCase(List1.List(ixi)), "Windows", vbTextCompare) > 0 Then
    58.  
    59.         List1.RemoveItem ixi
    60.  
    61.     End If
    62.    
    63.      If InStr(1, UCase(List1.List(ixi)), "WINNT\SchedLgU.txt", vbTextCompare) > 0 Then
    64.  
    65.         List1.RemoveItem ixi
    66.  
    67.     End If
    68.     If InStr(1, UCase(List1.List(ixi)), "Windows\SchedLgU.txt", vbTextCompare) > 0 Then
    69.  
    70.         List1.RemoveItem ixi
    71.  
    72.     End If
    73.    
    74.    
    75.      If InStr(1, UCase(List1.List(ixi)), "0ab10246f7cddc39151aba", vbTextCompare) > 0 Then
    76.         List1.RemoveItem ixi
    77.        
    78.     End If
    79.    
    80.    
    81.     If InStr(1, UCase(List1.List(ixi)), "WINNT\vmmreg32.dll", vbTextCompare) > 0 Then
    82.  
    83.         List1.RemoveItem ixi
    84.  
    85.     End If
    86.     If InStr(1, UCase(List1.List(ixi)), "Windows\vmmreg32.dll", vbTextCompare) > 0 Then
    87.  
    88.         List1.RemoveItem ixi
    89.  
    90.     End If
    91.    
    92.     If InStr(1, UCase(List1.List(ixi)), "MHX Antivirus and Antispyware Free Edition", vbTextCompare) > 0 Then
    93.  
    94.         List1.RemoveItem ixi
    95.  
    96.     End If
    97.  
    98.      If InStr(1, UCase(List1.List(ixi)), "Games\Neosteam\Update.exe", vbTextCompare) > 0 Then
    99.  
    100.         List1.RemoveItem ixi
    101.  
    102.     End If
    103.      If InStr(1, UCase(List1.List(ixi)), "\MSN\MSNCoreFiles\Update.exe", vbTextCompare) > 0 Then
    104.  
    105.         List1.RemoveItem ixi
    106.  
    107.     End If
    108.     Next
    109.             End If
    110.             Cont = FindNextFile(hSearch, WFD) ' Get next file
    111.         Wend
    112.         Cont = FindClose(hSearch)
    113.     End If
    114.     ' If there are sub-directories...
    115.     If nDir > 0 Then
    116.         ' Recursively walk into them...
    117.         For i = 0 To nDir - 1
    118.             FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
    119.         Next i
    120.     End If
    121.     Screen.MousePointer = vbDefault
    122. End Function

    The program debugs the line" DirCount = DirCount + 1" out of the code above.

    Is there a way to make it not overflow, there must be a limit on the number of dir count that gives me overflow.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Overflow Error?

    Maybe the "Dim i As Integer "and "DirCount" probably are overflowing as you may have more directories then 32767 which is Integer type. Also, you should define the xix variable and use Option Exolicit at the top of your module.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Overflow Error?

    excellent, thank you!!!

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