Results 1 to 5 of 5

Thread: Search Application won't search?

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Unhappy Search Application won't search?

    My search application isn't working. When the "Search" window pops up, the label stays frozen on "C:\". The application isn't freezing, just the search. Why? I can still use the buttons on it, and everything else seems to work fine.

    Please help!
    Last edited by minitech; May 20th, 2009 at 09:58 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Search Application won't search?

    Like many people, I am not a big fan of downloading entire projects unnecessarily. I'm fairly sure that you could just post the code for the method in question directly, at least as a first attempt.

    Also, I'm not sure that you have but just make sure you haven't included any binary files in that attachment as it's against forum rules. Always delete the bin and obj folders before zipping projects.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Search Application won't search?

    Fine. By the way, I haven't included the CMessageBox class. It's just a messagebox with fancy graphics.

    Form1 (main form):
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub txtSearch_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearch.GotFocus
    4.         If Me.txtSearch.Text = "Type your search here" Then
    5.             Me.txtSearch.ForeColor = Color.White
    6.             Me.txtSearch.Text = ""
    7.         End If
    8.     End Sub
    9.  
    10.     Private Sub txtSearch_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearch.LostFocus
    11.         If Me.txtSearch.Text = "" Then
    12.             Me.txtSearch.ForeColor = Color.Gray
    13.             Me.txtSearch.Text = "Type your search here"
    14.         End If
    15.     End Sub
    16.  
    17.     Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    18.         If e.KeyCode = Keys.X And e.Alt Then Me.Close()
    19.     End Sub
    20.  
    21.     Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseLeave
    22.         Dim cpos As New Point(Me.Location.X + Windows.Forms.Cursor.Position.X, Me.Location.Y + Windows.Forms.Cursor.Position.Y)
    23.         Dim rect As New Rectangle(Me.Location, Me.Size)
    24.         If Not rect.Contains(cpos) Then Me.Opacity = 0.75
    25.     End Sub
    26.  
    27.     Private Sub Any_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
    28.         Me.Opacity = 1.0#
    29.     End Sub
    30.  
    31.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    32.         Dim i As Integer = 0
    33.         AddHandler Me.MouseHover, AddressOf Any_MouseHover
    34.         While i < Me.Controls.Count
    35.             AddHandler Me.Controls(i).MouseHover, AddressOf Any_MouseHover
    36.             i += 1
    37.         End While
    38.     End Sub
    39.  
    40.     Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    41.         If Me.txtSearch.Text = "" Or Me.txtSearch.ForeColor = Color.Gray Then
    42.             Dim f As New CMessageBox("You must enter search terms!", "Search", SystemIcons.Exclamation)
    43.             f.ShowDialog()
    44.         Else
    45.             Dim f As New Searcher(Me.txtSearch.Text)
    46.             Me.Hide()
    47.             f.Owner = Me
    48.             f.Show()
    49.             f.Search()
    50.             Me.Show()
    51.             'AddHandler f.FormClosed, AddressOf ShowSelf
    52.         End If
    53.     End Sub
    54.     Private Sub ShowSelf(ByVal sender As Object, ByVal e As FormClosedEventArgs)
    55.         Me.Show()
    56.     End Sub
    57. End Class

    and Searcher (the searching form):
    vb.net Code:
    1. Public Class Searcher
    2.     Dim _searchdir As String = "C:\"
    3.     Dim _searchterm As String = ""
    4.     Structure ResultInfo
    5.         Dim FileName As String
    6.         Dim ParentDirectory As String
    7.     End Structure
    8.     Dim t As System.Threading.Thread
    9.     Delegate Sub NoArgsD()
    10.     Delegate Sub AddResultDef(ByVal arg As ResultInfo)
    11.     Delegate Sub SetTextDef(ByVal text As String)
    12.     Dim doaddresult As AddResultDef = New AddResultDef(AddressOf AddResult)
    13.     Dim dosetsttext As SetTextDef = New SetTextDef(AddressOf SetStatusText)
    14.     Dim dofinished As NoArgsD = New NoArgsD(AddressOf Finished)
    15.     Public Sub New(ByVal searchdir As String)
    16.  
    17.         ' This call is required by the Windows Form Designer.
    18.         InitializeComponent()
    19.  
    20.         ' Add any initialization after the InitializeComponent() call.
    21.         _searchdir = searchdir
    22.     End Sub
    23.     Private Sub Finished()
    24.         Me.lblCurrentSearch.Text = "Done."
    25.         Me.btnStopSearch.Visible = False
    26.         Dim f As New CMessageBox("Search complete.", "Search", SystemIcons.Information)
    27.         t = Nothing
    28.     End Sub
    29.     Public Sub Search()
    30.         t = New Threading.Thread(AddressOf InitSearch)
    31.         t.Start()
    32.     End Sub
    33.     Private Sub InitSearch()
    34.         On Error GoTo sub_exit
    35.         DoSearch(_searchdir)
    36.         Me.Invoke(dofinished)
    37. sub_exit:
    38.     End Sub
    39.     Private Sub DoSearch(ByVal dir As String)
    40.         Dim di, cdi As System.IO.DirectoryInfo
    41.         Dim fi As System.IO.FileInfo
    42.         cdi = New IO.DirectoryInfo(dir)
    43.         If cdi.Name.Contains(_searchterm) Then
    44.             Dim rs As ResultInfo
    45.             rs.FileName = cdi.Name
    46.             If Not cdi.Parent Is Nothing Then
    47.                 rs.ParentDirectory = cdi.Parent.FullName
    48.             Else
    49.                 rs.ParentDirectory = "My Computer"
    50.             End If
    51.         End If
    52.         For Each fi In cdi.GetFiles()
    53.             If fi.Name.Contains(_searchterm) Then
    54.                 Dim ri As ResultInfo
    55.                 ri.FileName = fi.Name
    56.                 ri.ParentDirectory = cdi.FullName
    57.                 Me.Invoke(doaddresult, ri)
    58.             End If
    59.         Next
    60.         For Each di In cdi.GetDirectories()
    61.             Me.Invoke(dosetsttext, "Currently Searching " & di.FullName)
    62.             DoSearch(di.FullName)
    63.         Next
    64.     End Sub
    65.     Private Sub AddResult(ByVal result As ResultInfo)
    66.         Dim lvi As New ListViewItem(New String() {result.FileName, result.ParentDirectory})
    67.         Me.lstSearchResults.Items.Add(lvi)
    68.         lvi = Nothing
    69.     End Sub
    70.     Private Sub SetStatusText(ByVal str As String)
    71.         Me.lblCurrentSearch.Text = str
    72.     End Sub
    73.  
    74.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    75.         If Not t Is Nothing Then
    76.             t.Abort()
    77.         End If
    78.         Me.Close()
    79.     End Sub
    80.  
    81.     Private Sub btnStopSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopSearch.Click
    82.         t.Abort()
    83.         Me.btnStopSearch.Visible = False
    84.         Me.lblCurrentSearch.Text = "Search stopped."
    85.     End Sub
    86. End Class

  4. #4

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Search Application won't search?

    Or could it just be slow? Google Desktop is indexing my files right now...
    Still, I waited a while for the "current directory" label to change, but nothing happened...

  5. #5

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Search Application won't search?

    Ok, not google desktop. I turned it off and waited a really long time, the label doesn't even change...

    What's going wrong? Also, the form behind it seems frozen. It won't hide. Also, if this is important, ShowInTaskbar is set to False on #1 and True on #2.

    I have no idea what's happening! Please help!

Tags for this Thread

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