how to stop the search in the middle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravindarjobs
    New Member
    • May 2007
    • 86

    how to stop the search in the middle

    hi......
    i am using ms access 2003,vb6

    i have a form.
    in that i have 2 buttons
    1. start search
    2 stop search


    when i click the "start search" button the fucntion SearchSystem() is called, it will search for a particular file in the computer(search es entire drives).

    the button "stop search" is intended to stop the search.

    but while the search is going on, i could not click "stop search", it is not enabled to click while the search is going on?

    how do i approach to stop the search?

    [CODE=vb]Function SearchSystem(Dr iveTypes As Integer, FileSpec As String, Optional oFolder = Empty) As Integer

    Dim fs As FileSystemObjec t
    Dim dc As Drives
    Dim oDrive As Drive
    Dim ofld As Folder
    Dim file
    Dim subdirs As New Collection
    Dim subdir
    Dim st As String

    Set fs = CreateObject("S cripting.FileSy stemObject")
    Set dc = fs.Drives

    On Error GoTo errorhandler:


    If oFolder <> "" Then
    If cap = 1 Then
    Label11.caption = " The applicaion is being searced for in " & oFolder
    Me.Refresh
    Me.Repaint
    Me.Refresh
    ElseIf cap = 2 Then
    Label11.caption = " The application is being searched for in " & oFolder
    Me.Refresh
    Me.Repaint
    Me.Refresh

    End If

    file = Dir$(oFolder & FileSpec)
    Do While Len(file)
    'File found
    file = oFolder & file

    If InStr(1, file, "IFs.exe") Then
    st = Replace(file, "IFs.exe", "")
    ChDir st
    Shell file, vbNormalFocus
    glob = glob + 1

    Exit Function


    ElseIf InStr(1, file, "Wdi32.exe" ) Then
    st = Replace(file, "Wdi32.exe" , "")
    ChDir st
    Shell file, vbNormalFocus
    glob = glob + 1

    Exit Function
    End If
    'Exit Sub



    Debug.Print file
    file = Dir$()
    Loop
    file = Dir$(oFolder & "*.*", vbDirectory)
    Do While Len(file)
    ' we've found a new directory
    If file = "." Or file = ".." Then
    ' exclude "." and ".."
    ElseIf (GetAttr(oFolde r & file) And vbDirectory) = 0 Then

    ' ignore regular files
    Else
    ' this is a directory, include the path in the collection
    subdirs.Add oFolder & file
    End If
    ' get next directory
    file = Dir$()
    Loop

    For Each subdir In subdirs
    If glob = 0 Then
    Call SearchSystem(Dr iveTypes, FileSpec, subdir & "\")
    Else

    Exit Function
    End If
    Next

    End If



    If oFolder = "" Then
    For Each oDrive In dc




    'Use bitwise expression to see if Drivetype is one of the Drivetypes we wish to search
    If (oDrive.DriveTy pe And DriveTypes) = oDrive.DriveTyp e Then

    'MsgBox ("searching" )
    'oDrive is a drive type we wish to search
    Debug.Print "Searching: " & oDrive.path
    If oDrive.IsReady Then Call SearchSystem(Dr iveTypes, FileSpec, oDrive.path & "\")
    End If
    Next 'oDrive
    Debug.Print "finished"

    End If

    Set fs = Nothing
    Set dc = Nothing

    'Exit Sub


    errorhandler:
    If Err.Number = 75 Then
    'Path/File access error (file locked for reading or doesn't exist?)
    Debug.Print Err.Description
    Resume Next

    ElseIf Err.Number = 52 Then

    End If


    End Function[/CODE]
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by ravindarjobs
    hi......
    i am using ms access 2003,vb6

    i have a form.
    in that i have 2 buttons
    1. start search
    2 stop search


    when i click the "start search" button the fucntion SearchSystem() is called, it will search for a particular file in the computer(search es entire drives).

    the button "stop search" is intended to stop the search.

    but while the search is going on, i could not click "stop search", it is not enabled to click while the search is going on?

    how do i approach to stop the search?

    i got your problem (but never checked code).

    when it enters into 'For' Loop you have to use a Flag(variable) for the condition

    Code:
    for........
      If strFlag = "Start" then
       <Do Some thing>
      else
       <Exit For>
      endif
    loop
    in stop button just write
    Code:
    strFlag = "Stop"
    i think this will help you.

    Comment

    • ravindarjobs
      New Member
      • May 2007
      • 86

      #3
      [
      If strFlag = "Start" then
      <Do Some thing>
      else
      <Exit For>
      endif
      loop[/CODE]



      thanq friend for your response

      but what is the type of the variabel strFlag
      i have declared it as string.
      even then i coludnt make it.......


      is this the below code what u suggest?


      Option Explicit
      dim strFlag as string
      private StartSearh_clic k(..)
      strFlag ="start"
      if strFlag="start" then
      SearchSystem()
      End if
      End sub


      private StopSearch_Clic k(..)
      strFlag="start"
      End sub

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Code:
        Option Explicit
        dim strFlag as string
        
        private StartSearh_click(..)
            strFlag="Start"
            SearchSystem()
        End sub
        
        
        private StopSearch_Click(..)
          strFlag="Stop"
        End sub
        
        Private sub searchSystem()
            For i =1 to EndOfSearchText
                if strFlag="Start" then 
                    <Start Search>
                Else
                    <End Search>
                End If
            Next i
        End Sub
        just try this way.

        Comment

        • ravindarjobs
          New Member
          • May 2007
          • 86

          #5
          thanq friend,

          your idea has helped me.

          Option Compare Database
          Option Explicit




          i used the following code.
          it worked perfectly.



          Private m_SearchStop As Boolean


          Private Sub cmdSearchStart_ Click()


          m_SearchStop = False
          SearchSystem()


          End Sub


          Private Sub cmdSearchStop_C lick()


          m_SearchStop = True


          End Sub


          Private Function SearchSystem() As Boolean


          DoEvents
          Do While Len(file) And Not m_SearchStop
          ...
          DoEvents
          Loop


          For Each subdir In subdirs
          DoEvents
          If m_SearchStop Then
          Exit For
          End If
          Next subdir


          End Function

          Comment

          Working...