home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / SearchMySt2118966302008.psc / frmSearch.frm < prev    next >
Text File  |  2008-06-30  |  13KB  |  444 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form frmSearch 
  4.    Caption         =   "Search VB"
  5.    ClientHeight    =   6015
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   10590
  9.    Icon            =   "frmSearch.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6015
  12.    ScaleWidth      =   10590
  13.    Begin VB.CheckBox chkRemAttr 
  14.       Caption         =   "Remove VB Attributes When Viewing"
  15.       Height          =   255
  16.       Left            =   5160
  17.       TabIndex        =   8
  18.       Top             =   240
  19.       Width           =   3135
  20.    End
  21.    Begin MSComctlLib.ImageList ImageList1 
  22.       Left            =   5040
  23.       Top             =   2760
  24.       _ExtentX        =   1005
  25.       _ExtentY        =   1005
  26.       BackColor       =   -2147483643
  27.       ImageWidth      =   16
  28.       ImageHeight     =   16
  29.       MaskColor       =   12632256
  30.       _Version        =   393216
  31.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  32.          NumListImages   =   6
  33.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  34.             Picture         =   "frmSearch.frx":08CA
  35.             Key             =   "cls"
  36.          EndProperty
  37.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  38.             Picture         =   "frmSearch.frx":0E64
  39.             Key             =   "ctl"
  40.          EndProperty
  41.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  42.             Picture         =   "frmSearch.frx":13FE
  43.             Key             =   "frm"
  44.          EndProperty
  45.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  46.             Picture         =   "frmSearch.frx":1998
  47.             Key             =   "bas"
  48.          EndProperty
  49.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  50.             Picture         =   "frmSearch.frx":1F32
  51.             Key             =   "Up"
  52.          EndProperty
  53.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  54.             Picture         =   "frmSearch.frx":24CC
  55.             Key             =   "Dn"
  56.          EndProperty
  57.       EndProperty
  58.    End
  59.    Begin VB.CommandButton cmdSrch 
  60.       Caption         =   "Search"
  61.       Height          =   285
  62.       Left            =   3480
  63.       TabIndex        =   7
  64.       Top             =   0
  65.       Width           =   855
  66.    End
  67.    Begin VB.CheckBox chkT 
  68.       Caption         =   "Controls"
  69.       Height          =   255
  70.       Index           =   3
  71.       Left            =   7800
  72.       TabIndex        =   6
  73.       Tag             =   "ctl"
  74.       Top             =   0
  75.       Width           =   975
  76.    End
  77.    Begin VB.CheckBox chkT 
  78.       Caption         =   "Cls Mods"
  79.       Height          =   255
  80.       Index           =   2
  81.       Left            =   6720
  82.       TabIndex        =   5
  83.       Tag             =   "cls"
  84.       Top             =   0
  85.       Width           =   1335
  86.    End
  87.    Begin VB.CheckBox chkT 
  88.       Caption         =   "Bas Mods"
  89.       Height          =   255
  90.       Index           =   1
  91.       Left            =   5520
  92.       TabIndex        =   4
  93.       Tag             =   "bas"
  94.       Top             =   0
  95.       Width           =   1335
  96.    End
  97.    Begin VB.CheckBox chkT 
  98.       Caption         =   "Forms"
  99.       Height          =   255
  100.       Index           =   0
  101.       Left            =   4680
  102.       TabIndex        =   3
  103.       Tag             =   "frm"
  104.       Top             =   0
  105.       Value           =   1  'Checked
  106.       Width           =   1335
  107.    End
  108.    Begin VB.CommandButton cmdAll 
  109.       Caption         =   "Show All Records"
  110.       Height          =   255
  111.       Left            =   9000
  112.       TabIndex        =   2
  113.       Top             =   0
  114.       Width           =   1455
  115.    End
  116.    Begin VB.TextBox txtSrch 
  117.       Height          =   285
  118.       Left            =   0
  119.       TabIndex        =   0
  120.       Top             =   0
  121.       Width           =   3375
  122.    End
  123.    Begin MSComctlLib.ListView LV 
  124.       Height          =   5535
  125.       Left            =   0
  126.       TabIndex        =   1
  127.       Top             =   480
  128.       Width           =   10455
  129.       _ExtentX        =   18441
  130.       _ExtentY        =   9763
  131.       View            =   3
  132.       LabelEdit       =   1
  133.       Sorted          =   -1  'True
  134.       MultiSelect     =   -1  'True
  135.       LabelWrap       =   -1  'True
  136.       HideSelection   =   -1  'True
  137.       OLEDragMode     =   1
  138.       FullRowSelect   =   -1  'True
  139.       _Version        =   393217
  140.       SmallIcons      =   "ImageList1"
  141.       ColHdrIcons     =   "ImageList1"
  142.       ForeColor       =   -2147483640
  143.       BackColor       =   -2147483643
  144.       BorderStyle     =   1
  145.       Appearance      =   1
  146.       OLEDragMode     =   1
  147.       NumItems        =   5
  148.       BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  149.          Text            =   "Name"
  150.          Object.Width           =   2646
  151.          ImageKey        =   "Up"
  152.       EndProperty
  153.       BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  154.          SubItemIndex    =   1
  155.          Text            =   "Type"
  156.          Object.Width           =   1323
  157.       EndProperty
  158.       BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  159.          SubItemIndex    =   2
  160.          Text            =   "Date"
  161.          Object.Width           =   4939
  162.       EndProperty
  163.       BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  164.          SubItemIndex    =   3
  165.          Text            =   "Size"
  166.          Object.Width           =   2540
  167.       EndProperty
  168.       BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  169.          SubItemIndex    =   4
  170.          Text            =   "Path"
  171.          Object.Width           =   6703
  172.       EndProperty
  173.    End
  174.    Begin VB.Menu LVPop 
  175.       Caption         =   ""
  176.       Visible         =   0   'False
  177.       Begin VB.Menu LVArr 
  178.          Caption         =   "View Selected File"
  179.          Index           =   0
  180.       End
  181.       Begin VB.Menu LVArr 
  182.          Caption         =   "Copy To..."
  183.          Index           =   1
  184.       End
  185.       Begin VB.Menu LVArr 
  186.          Caption         =   "Delete From Database"
  187.          Index           =   2
  188.       End
  189.    End
  190. End
  191. Attribute VB_Name = "frmSearch"
  192. Attribute VB_GlobalNameSpace = False
  193. Attribute VB_Creatable = False
  194. Attribute VB_PredeclaredId = True
  195. Attribute VB_Exposed = False
  196. 'Program needs a reference to
  197. ' Microsoft DAO Object Library (dao360.dll)
  198. 'If it shows as missing reference, you
  199. ' may need to register it,
  200. ' Start|Run|regsvr32.exe c:\[path]\dao360.dll
  201. 'Possible Locations:
  202. 'C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll
  203. 'C:\WINDOWS\ServicePackFiles\i386
  204. 'Download site
  205. 'http://www.domainpunch.com/support/articles/dao.php
  206. 'Do NOT need MS Access installed
  207. 'Note you can also drag files to an open
  208. ' VB Ide Project Window, see the
  209. ' LV_OLEStartDrag routine below
  210. Option Explicit
  211. Private DBPath As String
  212. Private DB As DAO.Database
  213. Private RecCnt As Long
  214. Private LVRatios As Variant
  215. Private Sub Form_Load()
  216.  Init
  217.  Show
  218.  DoEvents
  219.  If RecCnt = 0 Then
  220.   MsgBox "No records in the database." & vbNewLine & _
  221.     "Run the included BuildMyStuff vbp to add records"
  222.   Unload Me
  223.  Else
  224.   LV.ColumnHeaders(5).Text = "Path   (Database has " & RecCnt & " records)"
  225.  End If
  226. End Sub
  227. Private Sub Init()
  228.  DBPath = App.Path & "\Ref.mdb"
  229.  Set DB = OpenDatabase(DBPath)
  230.  RecCnt = DBRecCnt
  231.  Set oIni = New cIni
  232.  oIni.Path = App.Path & "\Search.ini"
  233.  LVRatios = Array(, 0.142, 0.1, 0.164, 0.136, 0.45)
  234.  LoadSettings
  235. End Sub
  236. Private Sub LoadSettings()
  237.  Dim i As Long
  238.  With oIni
  239.   .Section = "Main Settings"
  240.   .Key = "FLeft": Left = .Value
  241.   .Key = "FTop": Top = .Value
  242.   .Key = "FWidth": Width = .Value
  243.   .Key = "FHeight": Height = .Value
  244.   For i = 0 To 3
  245.    .Key = "FType" & i: chkT(i).Value = .Value
  246.   Next
  247.   .Key = "FAttr":  chkRemAttr.Value = .Value
  248.  End With
  249. End Sub
  250. Private Sub SaveSettings()
  251.  Dim i As Long
  252.  With oIni
  253.   .Section = "Main Settings"
  254.   .Key = "FLeft": .Value = Left
  255.   .Key = "FTop": .Value = Top
  256.   .Key = "FWidth": .Value = Width
  257.   .Key = "FHeight": .Value = Height
  258.   For i = 0 To 3
  259.    .Key = "FType" & i: .Value = chkT(i).Value
  260.   Next
  261.   .Key = "FAttr": .Value = chkRemAttr.Value
  262.  End With
  263. End Sub
  264. Private Sub Form_Resize()
  265.  Dim i As Long
  266.  If WindowState <> vbMinimized Then
  267.  'listview column width ratios
  268.  LV.Move 0, 480, ScaleWidth, ScaleHeight
  269.  For i = 1 To LV.ColumnHeaders.Count
  270.   LV.ColumnHeaders(i).Width = LVRatios(i) * LV.Width
  271.  Next
  272.  End If
  273. End Sub
  274.  
  275. Private Sub Form_Unload(Cancel As Integer)
  276.  SaveSettings
  277.  Set oIni = Nothing
  278.  DB.Close
  279.  Set DB = Nothing
  280. End Sub
  281. Private Sub cmdAll_Click()
  282.  LoadRS DB.OpenRecordset("Main")
  283. End Sub
  284. Private Sub cmdSrch_Click()
  285.  If Len(txtSrch.Text) Then
  286.   DoSearch
  287.  End If
  288. End Sub
  289.  
  290. Private Sub LV_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
  291.  Dim i As Long
  292.  For i = 1 To LV.ColumnHeaders.Count
  293.   LV.ColumnHeaders(i).Icon = 0
  294.  Next
  295.  With LV
  296.   .SortKey = ColumnHeader.Index - 1
  297.   .SortOrder = .SortOrder Xor 1
  298.   LV.ColumnHeaders(ColumnHeader.Index).Icon = IIf(.SortOrder = lvwAscending, "Up", "Dn")
  299.  End With
  300. End Sub
  301.  
  302. Private Sub LV_ItemClick(ByVal Item As MSComctlLib.ListItem)
  303.  Caption = Item.SubItems(4)
  304. End Sub
  305.  
  306. Private Sub LV_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  307.  Dim LI As ListItem
  308.  If Button = vbRightButton Then
  309.   Set LI = LV.HitTest(x, y)
  310.   If Not LI Is Nothing Then
  311.    LI.Selected = True
  312.    LVArr(0).Enabled = LVSelCount(LV) < 2
  313.    PopupMenu LVPop
  314.   End If
  315.  End If
  316. End Sub
  317.  
  318. Private Sub LV_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
  319.  Dim i As Long
  320.  For i = 1 To LV.ListItems.Count
  321.   With LV.ListItems(i)
  322.    If .Selected Then
  323.     Data.Files.Add .SubItems(4)
  324.    End If
  325.   End With
  326.  Next
  327.  Data.SetData , vbCFFiles
  328. End Sub
  329.  
  330. Private Sub LVArr_Click(Index As Integer)
  331.  Select Case Index
  332.   Case 0 'view
  333.    DoView LV.SelectedItem
  334.   Case 1 'copy
  335.    DoCopy
  336.   Case 2 'delete
  337.    DoDelete
  338.  End Select
  339. End Sub
  340. Private Sub DoDelete()
  341.  Dim i As Long
  342.  Dim RS As Recordset
  343.  For i = LV.ListItems.Count To 1 Step -1
  344.   With LV.ListItems(i)
  345.    If .Selected Then
  346.     Set RS = DB.OpenRecordset("Select * From Main Where Index = " & Val(.Key))
  347.     RS.Delete
  348.     LV.ListItems.Remove i
  349.    End If
  350.   End With
  351.  Next
  352. End Sub
  353. Private Sub DoView(LI As ListItem)
  354.  Dim Frm As Form
  355.  Dim RS As Recordset
  356.  Set RS = DB.OpenRecordset("Select * From Main Where Index = " & Val(LI.Key))
  357.  Set Frm = New frmView
  358.  Frm.Caption = RS!Path
  359.  If chkRemAttr.Value = vbChecked Then
  360.   Frm.Text = StripAttr(RS!Text)
  361.  Else
  362.   Frm.Text = RS!Text
  363.  End If
  364.  Frm.Search = txtSrch.Text
  365.  Frm.Show vbModal
  366. End Sub
  367. Private Sub txtSrch_KeyPress(KeyAscii As Integer)
  368.  If KeyAscii = vbKeyReturn Then
  369.   KeyAscii = 0
  370.   DoSearch
  371.  End If
  372. End Sub
  373. Private Sub DoSearch()
  374.  Dim RS As Recordset
  375.  Dim SQL As String
  376.  Dim Srch As String
  377.  Srch = Quote("*" & txtSrch.Text & "*")
  378.  SQL = "Select * From Main Where (Text Like " & Srch & " Or Name Like " & Srch & ")" & _
  379.    " And (" & TypeSQL & ")"
  380.  Set RS = DB.OpenRecordset(SQL)
  381.  If RS.EOF Then
  382.   Caption = "Nothing Found"
  383.   Exit Sub
  384.  End If
  385.  LoadRS RS
  386. End Sub
  387. Private Function TypeSQL() As String
  388.  Dim i As Long
  389.  For i = 0 To 3
  390.   If chkT(i).Value = vbChecked Then
  391.    If Len(TypeSQL) Then
  392.     TypeSQL = TypeSQL & "Or Type = " & Quote(chkT(i).Tag)
  393.    Else
  394.     TypeSQL = TypeSQL & " Type = " & Quote(chkT(i).Tag)
  395.    End If
  396.    TypeSQL = TypeSQL & " "
  397.   End If
  398.  Next
  399. End Function
  400. Private Sub LoadRS(RS As Recordset)
  401.  Dim i As Long
  402.  Screen.MousePointer = vbHourglass
  403.  LV.ListItems.Clear
  404.  RS.MoveLast: RS.MoveFirst
  405.  For i = 1 To RS.RecordCount
  406.   With LV.ListItems.Add
  407.    .Selected = False
  408.    .Text = RS!Name
  409.    .SubItems(1) = RS!Type
  410.    .SmallIcon = CStr(RS!Type)
  411.    .SubItems(2) = Format$(RS!Date, "yyyy-mm-dd hh-nn-ss")
  412.    .SubItems(3) = Format$(RS!Size, "@@@@@@@")
  413.    .SubItems(4) = RS!Path
  414.    .Key = RS!Index & "k"
  415.   End With
  416.   RS.MoveNext
  417.  Next
  418.  Screen.MousePointer = vbDefault
  419.  Caption = LV.ListItems.Count & " Items Found"
  420. End Sub
  421. Private Sub DoCopy()
  422.  Dim RS As Recordset
  423.  Dim BF As String, i As Long
  424.  BF = BrowseForFolderByPath("C:\VB6", hWnd, "Select Folder")
  425.  If Len(BF) = 0 Then Exit Sub
  426.  For i = 1 To LV.ListItems.Count
  427.   With LV.ListItems(i)
  428.    If .Selected Then
  429.     Set RS = DB.OpenRecordset("Select Path From Main Where Index = " & Val(.Key))
  430.     FileCopy RS!Path, QualifyPath(BF) & FileTitle(RS!Path)
  431.    End If
  432.   End With
  433.  Next
  434. End Sub
  435. Private Function DBRecCnt() As Long
  436.  Dim RS As Recordset
  437.  Set RS = DB.OpenRecordset("Main")
  438.  If Not RS.EOF Then
  439.   RS.MoveLast: RS.MoveFirst
  440.   DBRecCnt = RS.RecordCount
  441.  End If
  442.  RS.Close
  443. End Function
  444.