home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / MISC / FILECTS / SEEK.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1996-09-16  |  9.7 KB  |  274 lines

  1. VERSION 5.00
  2. Begin VB.Form WinSeek 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "WinSeek"
  6.    ClientHeight    =   4020
  7.    ClientLeft      =   1920
  8.    ClientTop       =   1890
  9.    ClientWidth     =   3720
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   8.25
  13.       Charset         =   1
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H00000080&
  20.    Height          =   4395
  21.    Left            =   1875
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    ScaleHeight     =   4020
  25.    ScaleWidth      =   3720
  26.    Top             =   1560
  27.    Width           =   3810
  28.    Begin VB.PictureBox Picture2 
  29.       BorderStyle     =   0  'None
  30.       Height          =   2895
  31.       Left            =   720
  32.       ScaleHeight     =   2895
  33.       ScaleWidth      =   3855
  34.       TabIndex        =   8
  35.       Top             =   1080
  36.       Visible         =   0   'False
  37.       Width           =   3855
  38.       Begin VB.ListBox lstFoundFiles 
  39.          Height          =   2235
  40.          Left            =   120
  41.          TabIndex        =   11
  42.          Top             =   480
  43.          Width           =   3375
  44.       End
  45.       Begin VB.Label lblCount 
  46.          Caption         =   "0"
  47.          Height          =   255
  48.          Left            =   1200
  49.          TabIndex        =   10
  50.          Top             =   120
  51.          Width           =   1095
  52.       End
  53.       Begin VB.Label lblfound 
  54.          Caption         =   "&Files Found:"
  55.          Height          =   255
  56.          Left            =   120
  57.          TabIndex        =   9
  58.          Top             =   120
  59.          Width           =   1095
  60.       End
  61.    End
  62.    Begin VB.PictureBox Picture1 
  63.       BorderStyle     =   0  'None
  64.       Height          =   2895
  65.       Left            =   0
  66.       ScaleHeight     =   2895
  67.       ScaleWidth      =   3735
  68.       TabIndex        =   2
  69.       Top             =   120
  70.       Width           =   3735
  71.       Begin VB.DriveListBox drvList 
  72.          Height          =   1530
  73.          Left            =   2040
  74.          TabIndex        =   7
  75.          Top             =   480
  76.          Width           =   1575
  77.       End
  78.       Begin VB.DirListBox dirList 
  79.          Height          =   1695
  80.          Left            =   2040
  81.          TabIndex        =   6
  82.          Top             =   960
  83.          Width           =   1575
  84.       End
  85.       Begin VB.FileListBox filList 
  86.          Height          =   2040
  87.          Left            =   120
  88.          TabIndex        =   5
  89.          Top             =   480
  90.          Width           =   1815
  91.       End
  92.       Begin VB.TextBox txtSearchSpec 
  93.          Height          =   285
  94.          Left            =   2040
  95.          TabIndex        =   4
  96.          Text            =   "*.*"
  97.          Top             =   120
  98.          Width           =   1575
  99.       End
  100.       Begin VB.Label lblCriteria 
  101.          Caption         =   "Search &Criteria:"
  102.          Height          =   255
  103.          Left            =   600
  104.          TabIndex        =   3
  105.          Top             =   120
  106.          Width           =   1335
  107.       End
  108.    End
  109.    Begin VB.CommandButton cmdSearch 
  110.       BackColor       =   &H00C0C0C0&
  111.       Caption         =   "&Search"
  112.       Default         =   -1  'True
  113.       Height          =   720
  114.       Left            =   480
  115.       TabIndex        =   0
  116.       Top             =   3000
  117.       Width           =   1200
  118.    End
  119.    Begin VB.CommandButton cmdExit 
  120.       BackColor       =   &H00C0C0C0&
  121.       Caption         =   "E&xit"
  122.       Height          =   720
  123.       Left            =   2040
  124.       TabIndex        =   1
  125.       Top             =   3000
  126.       Width           =   1200
  127.    End
  128. Option Explicit
  129. Dim SearchFlag As Integer   ' Used as flag for cancel and other operations.
  130. Private Sub cmdExit_Click()
  131.     If cmdExit.Caption = "E&xit" Then
  132.         End
  133.     Else                    ' If user chose Cancel, just end Search.
  134.         SearchFlag = False
  135.     End If
  136. End Sub
  137. Private Sub cmdSearch_Click()
  138. ' Initialize for search, then perform recursive search.
  139. Dim FirstPath As String, DirCount As Integer, NumFiles As Integer
  140. Dim result As Integer
  141.   ' Check what the user did last.
  142.     If cmdSearch.Caption = "&Reset" Then  ' If just a reset, initialize and exit.
  143.         ResetSearch
  144.         txtSearchSpec.SetFocus
  145.         Exit Sub
  146.     End If
  147.     ' Update dirList.Path if it is different from the currently
  148.     ' selected directory, otherwise perform the search.
  149.     If dirList.Path <> dirList.List(dirList.ListIndex) Then
  150.         dirList.Path = dirList.List(dirList.ListIndex)
  151.         Exit Sub         ' Exit so user can take a look before searching.
  152.     End If
  153.     ' Continue with the search.
  154.     Picture2.Move 0, 0
  155.     Picture1.Visible = False
  156.     Picture2.Visible = True
  157.     cmdExit.Caption = "Cancel"
  158.     filList.Pattern = txtSearchSpec.Text
  159.     FirstPath = dirList.Path
  160.     DirCount = dirList.ListCount
  161.     ' Start recursive direcory search.
  162.     NumFiles = 0                       ' Reset found files indicator.
  163.     result = DirDiver(FirstPath, DirCount, "")
  164.     filList.Path = dirList.Path
  165.     cmdSearch.Caption = "&Reset"
  166.     cmdSearch.SetFocus
  167.     cmdExit.Caption = "E&xit"
  168. End Sub
  169. Private Function DirDiver(NewPath As String, DirCount As Integer, BackUp As String) As Integer
  170. '  Recursively search directories from NewPath down...
  171. '  NewPath is searched on this recursion.
  172. '  BackUp is origin of this recursion.
  173. '  DirCount is number of subdirectories in this directory.
  174. Static FirstErr As Integer
  175. Dim DirsToPeek As Integer, AbandonSearch As Integer, ind As Integer
  176. Dim OldPath As String, ThePath As String, entry As String
  177. Dim retval As Integer
  178.     SearchFlag = True           ' Set flag so the user can interrupt.
  179.     DirDiver = False            ' Set to True if there is an error.
  180.     retval = DoEvents()         ' Check for events (for instance, if the user chooses Cancel).
  181.     If SearchFlag = False Then
  182.         DirDiver = True
  183.         Exit Function
  184.     End If
  185.     On Local Error GoTo DirDriverHandler
  186.     DirsToPeek = dirList.ListCount                  ' How many directories below this?
  187.     Do While DirsToPeek > 0 And SearchFlag = True
  188.         OldPath = dirList.Path                      ' Save old path for next recursion.
  189.         dirList.Path = NewPath
  190.         If dirList.ListCount > 0 Then
  191.             ' Get to the node bottom.
  192.             dirList.Path = dirList.List(DirsToPeek - 1)
  193.             AbandonSearch = DirDiver((dirList.Path), DirCount%, OldPath)
  194.         End If
  195.         ' Go up one level in directories.
  196.         DirsToPeek = DirsToPeek - 1
  197.         If AbandonSearch = True Then Exit Function
  198.     Loop
  199.     ' Call function to enumerate files.
  200.     If filList.ListCount Then
  201.         If Len(dirList.Path) <= 3 Then             ' Check for 2 bytes/character
  202.             ThePath = dirList.Path                  ' If at root level, leave as is...
  203.         Else
  204.             ThePath = dirList.Path + "\"            ' Otherwise put "\" before the filename.
  205.         End If
  206.         For ind = 0 To filList.ListCount - 1        ' Add conforming files in this directory to the list box.
  207.             entry = ThePath + filList.List(ind)
  208.             lstFoundFiles.AddItem entry
  209.             lblCount.Caption = Str(Val(lblCount.Caption) + 1)
  210.         Next ind
  211.     End If
  212.     If BackUp <> "" Then        ' If there is a superior directory, move it.
  213.         dirList.Path = BackUp
  214.     End If
  215.     Exit Function
  216. DirDriverHandler:
  217.     If Err = 7 Then             ' If Out of Memory error occurs, assume the list box just got full.
  218.         DirDiver = True         ' Create Msg and set return value AbandonSearch.
  219.         MsgBox "You've filled the list box. Abandoning search..."
  220.         Exit Function           ' Note that the exit procedure resets Err to 0.
  221.     Else                        ' Otherwise display error message and quit.
  222.         MsgBox Error
  223.         End
  224.     End If
  225. End Function
  226. Private Sub DirList_Change()
  227.     ' Update the file list box to synchronize with the directory list box.
  228.     filList.Path = dirList.Path
  229. End Sub
  230. Private Sub DirList_LostFocus()
  231.     dirList.Path = dirList.List(dirList.ListIndex)
  232. End Sub
  233. Private Sub DrvList_Change()
  234.     On Error GoTo DriveHandler
  235.     dirList.Path = drvList.Drive
  236.     Exit Sub
  237. DriveHandler:
  238.     drvList.Drive = dirList.Path
  239.     Exit Sub
  240. End Sub
  241. Private Sub Form_Load()
  242.     Picture2.Move 0, 0
  243.     Picture2.Width = WinSeek.ScaleWidth
  244.     Picture2.BackColor = WinSeek.BackColor
  245.     lblCount.BackColor = WinSeek.BackColor
  246.     lblCriteria.BackColor = WinSeek.BackColor
  247.     lblfound.BackColor = WinSeek.BackColor
  248.     Picture1.Move 0, 0
  249.     Picture1.Width = WinSeek.ScaleWidth
  250.     Picture1.BackColor = WinSeek.BackColor
  251. End Sub
  252. Private Sub Form_Unload(Cancel As Integer)
  253.     End
  254. End Sub
  255. Private Sub ResetSearch()
  256.     ' Reinitialize before starting a new search.
  257.     lstFoundFiles.Clear
  258.     lblCount.Caption = 0
  259.     SearchFlag = False                  ' Flag indicating search in progress.
  260.     Picture2.Visible = False
  261.     cmdSearch.Caption = "&Search"
  262.     cmdExit.Caption = "E&xit"
  263.     Picture1.Visible = True
  264.     dirList.Path = CurDir: drvList.Drive = dirList.Path ' Reset the path.
  265. End Sub
  266. Private Sub txtSearchSpec_Change()
  267.     ' Update file list box if user changes pattern.
  268.     filList.Pattern = txtSearchSpec.Text
  269. End Sub
  270. Private Sub txtSearchSpec_GotFocus()
  271.     txtSearchSpec.SelStart = 0          ' Highlight the current entry.
  272.     txtSearchSpec.SelLength = Len(txtSearchSpec.Text)
  273. End Sub
  274.