Results 1 to 9 of 9

Thread: Search from a text box

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Search from a text box

    Hey guys I have a text box, and i was wondering if it was possible to search a computer from that textbox. Say if text1 had notepad.exe in it. I press a button and the computer searchs for that file and says file found if it did.

    Thanks!!!!

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Search from a text box

    Justin, there are so many threads and expamples in the code bank and in the classic vb (this) forum. You better put a search

  3. #3
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Search from a text box

    This one is an identical thread to your one.
    http://www.vbforums.com/showthread.p...ht=File+Search

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Search from a text box

    Thanks, so I grabbed soem code out of that thread as the folllowing...

    VB Code:
    1. If txtFrmSlctn.Text = "Stainless Steel" Then
    2.    
    3.           optFrmSS.Value = True
    4.    
    5.          ElseIf txtFrmSlctn.Text = "Epoxy" ThenPublic Function RecurseFolderList(FolderName As String)  As Boolean
    6.        
    7.    
    8.       On Error Resume Next
    9.    
    10.       Dim fso, f, fc, fj, f1
    11.    
    12.        
    13.    
    14.        Set fso = CreateObject("Scripting.FileSystemObject")
    15.    
    16.      
    17.       If Err.Number > 0 Then
    18.  
    19.           RecurseFolderList = False
    20.  
    21.           Exit Function
    22.  
    23.       End If
    24.  
    25.       On Error GoTo 0
    26.  
    27.       If fso.FolderExists(FolderName) Then
    28.  
    29.        
    30.  
    31.           Set f = fso.GetFolder(FolderName)
    32.  
    33.           Set fc = f.Subfolders
    34.  
    35.           Set fj = f.Files
    36.  
    37.           'For each subfolder in the Folder
    38.  
    39.            For Each f1 In fc
    40.  
    41.            'Do something with the Folder Name
    42.  
    43.            Debug.Print f1
    44.  
    45.              'Then recurse this function with the sub-folder to get any'
    46.  
    47.             ' sub-folders
    48.  
    49.              RecurseFolderList (f1)
    50.  
    51.            Next
    52.  
    53.              'For each folder check for any files
    54.  
    55.              For Each f1 In fj
    56.  
    57.                  Debug.Print f1 'This is when the file will be listed
    58.  
    59.              Next
    60.          
    61.  
    62.           Set f = Nothing
    63.  
    64.           Set fc = Nothing
    65.  
    66.           Set fj = Nothing
    67.  
    68.           Set f1 = Nothing
    69.  
    70.       Else
    71.  
    72.           RecurseFolderList = False
    73.  
    74.       End If
    75.  
    76.       Set fso = Nothing
    77.  
    78.       End Function

    In this new case, can the code be modified to search for notepad.exe on the hard drive.


    And and such could it be deleted if it was found.

    And does this particular code need me to refernece the FileSystemObject?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search from a text box

    Quote Originally Posted by Justin M
    And does this particular code need me to refernece the FileSystemObject?
    If you use the FSO, it needs to be referenced.

    I prefer using this API
    Code:
    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

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Search from a text box

    Hmm, I don't see File System Object in the referenes, is it known under another name?
    Last edited by Justin M; Aug 28th, 2007 at 11:13 PM.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search from a text box

    Microsoft Scripting Runtime is what you are looking for.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Search from a text box

    Hmm I dont think I have a microsoft scripting runtime , but i have a microsoft script control 1.0 , would that be the same thing?

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search from a text box

    Do Project/References

    Microsoft Scripting Run time is right below the Microsoft Script Control in the list.

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