home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / findaf1a / frmfindf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-05  |  4.7 KB  |  159 lines

  1. VERSION 5.00
  2. Begin VB.Form frmFindFile 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Find File..."
  5.    ClientHeight    =   3360
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5880
  9.    Icon            =   "frmFindFile.frx":0000
  10.    LinkTopic       =   "frmFindFile"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3360
  14.    ScaleWidth      =   5880
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.ComboBox cmbString 
  17.       Height          =   315
  18.       Left            =   120
  19.       TabIndex        =   5
  20.       Top             =   220
  21.       Width           =   2655
  22.    End
  23.    Begin VB.CommandButton cmdCancel 
  24.       Cancel          =   -1  'True
  25.       Caption         =   "&Cancel"
  26.       Height          =   375
  27.       Left            =   4560
  28.       TabIndex        =   4
  29.       Top             =   180
  30.       Width           =   1095
  31.    End
  32.    Begin VB.CommandButton cmdFind 
  33.       Caption         =   "&Find File"
  34.       Default         =   -1  'True
  35.       Height          =   375
  36.       Left            =   2880
  37.       TabIndex        =   0
  38.       Top             =   180
  39.       Width           =   1095
  40.    End
  41.    Begin VB.DirListBox Dir1 
  42.       Height          =   2115
  43.       Left            =   120
  44.       TabIndex        =   2
  45.       Top             =   1080
  46.       Width           =   2655
  47.    End
  48.    Begin VB.DriveListBox Drive1 
  49.       Height          =   315
  50.       Left            =   120
  51.       TabIndex        =   1
  52.       Top             =   720
  53.       Width           =   2655
  54.    End
  55.    Begin VB.FileListBox File1 
  56.       Height          =   2430
  57.       Left            =   2880
  58.       TabIndex        =   3
  59.       Top             =   720
  60.       Width           =   2895
  61.    End
  62. Attribute VB_Name = "frmFindFile"
  63. Attribute VB_GlobalNameSpace = False
  64. Attribute VB_Creatable = False
  65. Attribute VB_PredeclaredId = True
  66. Attribute VB_Exposed = False
  67. ' FindFile by Amir Malik
  68. ' website: http://amir142.cjb.net
  69. ' e-mail : amir@infoteen.com
  70. Option Explicit
  71. Private mbIgnoreListClick As Boolean
  72. Private Sub cmbString_Click()
  73.     If Not mbIgnoreListClick Then
  74.         'Click code goes here
  75.     End If
  76. End Sub
  77. Private Sub cmbString_KeyPress(KeyAscii As Integer)
  78.         Dim sSearchText As String
  79.         Dim lReturn As Long
  80.         
  81.         If KeyAscii = 13 Then
  82.             cmbString_Click
  83.             KeyAscii = 0
  84.         Else
  85.             sSearchText = Left$(cmbString.Text, cmbString.SelStart) & Chr$(KeyAscii)
  86.             lReturn = SendMessage(cmbString.hWnd, CB_FINDSTRING, -1, ByVal sSearchText)
  87.             If lReturn <> CB_ERR Then
  88.                 mbIgnoreListClick = True
  89.                 cmbString.ListIndex = lReturn
  90.                 mbIgnoreListClick = False
  91.                 cmbString.Text = cmbString.List(lReturn)
  92.                 cmbString.SelStart = Len(sSearchText)
  93.                 cmbString.SelLength = Len(cmbString.Text)
  94.                 KeyAscii = 0
  95.             End If
  96.         End If
  97. End Sub
  98. Private Sub cmdCancel_Click()
  99.     End
  100. End Sub
  101. Private Sub cmdFind_Click()
  102.     ReDim sArray(0) As String
  103.     Call DirWalk(cmbString, Dir1.Path, sArray)
  104.     cmbString.AddItem cmbString
  105. End Sub
  106. Sub DirWalk(ByVal sPattern As String, ByVal CurrDir As String, sFound() As String)
  107. Dim i As Integer
  108. Dim sCurrPath As String
  109. Dim sFile As String
  110. Dim ii As Integer
  111. Dim iFiles As Integer
  112. Dim iLen As Integer
  113. If Right$(CurrDir, 1) <> "\" Then
  114.     Dir1.Path = CurrDir & "\"
  115.     Dir1.Path = CurrDir
  116. End If
  117. For i = 0 To Dir1.ListCount
  118.     If Dir1.List(i) <> "" Then
  119.         DoEvents
  120.         Call DirWalk(sPattern, Dir1.List(i), sFound)
  121.     Else
  122.         If Right$(Dir1.Path, 1) = "\" Then
  123.             sCurrPath = Left(Dir1.Path, Len(Dir1.Path) - 1)
  124.         Else
  125.             sCurrPath = Dir1.Path
  126.         End If
  127.         File1.Path = sCurrPath
  128.         File1.Pattern = sPattern
  129.         If File1.ListCount > 0 Then 'matching files found in the directory
  130.             For ii = 0 To File1.ListCount - 1
  131.                 ReDim Preserve sFound(UBound(sFound) + 1)
  132.                 sFound(UBound(sFound) - 1) = sCurrPath & "\" & File1.List(ii)
  133.             Next ii
  134.         End If
  135.         iLen = Len(Dir1.Path)
  136.         Do While Mid(Dir1.Path, iLen, 1) <> "\"
  137.             iLen = iLen - 1
  138.         Loop
  139.         Dir1.Path = Mid(Dir1.Path, 1, iLen)
  140.     End If
  141. Next i
  142. End Sub
  143. Private Sub Dir1_Change()
  144.     File1.Path = Dir1.Path
  145. End Sub
  146. Private Sub Drive1_Change()
  147.     Dir1.Path = Drive1.Drive
  148. End Sub
  149. Private Sub Form_Load()
  150.     Dim lne$, file
  151.     file = App.Path & "\recent.txt"
  152.     Open file For Input As #1
  153.     Do While Not EOF(1)
  154.         Line Input #1, lne$
  155.         cmbString.AddItem lne$
  156.     Loop
  157.     Close #1
  158. End Sub
  159.