Solved

Adding  a stop button and pause button to file searching : vb6

Posted on 2004-09-26
3
263 Views
Last Modified: 2012-05-05
Id like to add a stop button and pause button to my code when a search is being processed.


Please Add

1 text box
1 command button

1 stop button    ' please add
1 paue button   ' please add


Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long
Private Const MAX_PATH = 260

Private Sub Command1_Click()
 
    Dim tempStr As String, Ret As Long
    'create a buffer string
    tempStr = String(MAX_PATH, 0)
    'returns 1 when successfull, 0 when failed
    Ret = SearchTreeForFile("c:\", Text1.Text, tempStr)
   
   
    If Ret <> 0 Then
       
       MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
   
    Else
        MsgBox "File not found!"
    End If

End Sub
0
Comment
Question by:Jimmyx1000
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Hi Jimmyx1000,

There is now way we can add this functionality with the code you have presented.

The line that actually does the search

     Ret = SearchTreeForFile("c:\", Text1.Text, tempStr)

appears to be a blocking call to an external function, meaning it doesn't return until it is finished.   To implement the Stop and Pause features, you would need to modify the SearchTreeForFile() function.

Regards,

Idle_Mind
0
 
LVL 1

Accepted Solution

by:
VBtorment earned 500 total points
Comment Utility
Maybe this is helpfull
Not a nice solution but it works.

Option Explicit

Private bWait As Boolean
Private sWaitDir As String

Private Const MAX_PATH = 260
   
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
 
Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type

Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

Private Function TrimNull(startstr As String) As String
Dim pos As Integer

    pos = InStr(startstr, Chr$(0))
    If pos Then
        TrimNull = Left$(startstr, pos - 1)
        Exit Function
    End If
     TrimNull = startstr
End Function

Private Function bsl(Path$) As String
'Always return backslash at end of string
    If Right$(Path$, 1) = "\" Then
        bsl = Path$
    Else
        bsl = Path$ & "\"
    End If
End Function

Sub CountFolders(sPath$)
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
Dim cont As Integer
Dim sFile As String

       
    While bWait 'wait for bwait to turn false again(not very nice but it works)
        DoEvents
    Wend
   
    cont = True
    sPath$ = bsl(sPath$)
    hFile = FindFirstFile(sPath & "*.*" & Chr$(0), WFD)
    If hFile <> -1 Then
        While cont
            sFile = TrimNull(WFD.cFileName)
            If (sFile <> ".") And (sFile <> "..") Then
                If (WFD.dwFileAttributes And vbDirectory) Then 'Folders
                    CountFolders sPath$ & sFile 'recurse
                Else    'files
                    Label1.Caption = sPath$ & sFile
                    DoEvents
                End If
            End If
            cont = FindNextFile(hFile, WFD)
        Wend
    End If
    Call FindClose(hFile)
End Sub


Private Sub cmdPause_Click()
    bWait = Not bWait
End Sub

Private Sub cmdStart_Click()
    bWait = False
    Call CountFolders("C:\")
End Sub

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now