Solved

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

Posted on 2004-09-26
3
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12156643
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
ID: 12162894
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 104
VB6 - Compare and highlight cell not the same 3 61
clicking a shape in a frame array vb6 3 54
Modify Text File with Excel Macro 13 45
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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