home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch02 / ch02.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-10-31  |  3.2 KB  |  105 lines

  1. VERSION 5.00
  2. Begin VB.Form ch02 
  3.    Caption         =   "ListBox Search Example"
  4.    ClientHeight    =   6030
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6720
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   6030
  11.    ScaleWidth      =   6720
  12.    Begin VB.CommandButton Command3 
  13.       Caption         =   "Performance"
  14.       Height          =   495
  15.       Left            =   3360
  16.       TabIndex        =   3
  17.       Top             =   1920
  18.       Width           =   1575
  19.    End
  20.    Begin VB.CommandButton Command2 
  21.       Caption         =   "Find String"
  22.       Height          =   495
  23.       Left            =   3360
  24.       TabIndex        =   2
  25.       Top             =   1320
  26.       Width           =   1575
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "Load List"
  30.       Height          =   495
  31.       Left            =   3360
  32.       TabIndex        =   1
  33.       Top             =   720
  34.       Width           =   1575
  35.    End
  36.    Begin VB.ListBox List1 
  37.       Height          =   2565
  38.       Left            =   360
  39.       TabIndex        =   0
  40.       Top             =   720
  41.       Width           =   2175
  42.    End
  43. Attribute VB_Name = "ch02"
  44. Attribute VB_GlobalNameSpace = False
  45. Attribute VB_Creatable = False
  46. Attribute VB_PredeclaredId = True
  47. Attribute VB_Exposed = False
  48. Option Explicit
  49. Const RNDSEARCH% = 50
  50. ' Fill the listbox with some sample text
  51. Sub Command1_Click()
  52.     Dim x%
  53.     For x% = 1 To 500
  54.         List1.AddItem "Listbox entry #" + Str$(x%)
  55.     Next x%
  56. End Sub
  57. ' This code demonstrates a fast search for a string in
  58. ' the list box
  59. Sub Command2_Click()
  60.     Dim hw&, t&
  61.     hw& = List1.hWnd    ' Get the window handle for the list box
  62.     t& = SendMessageByString&(hw&, LB_FINDSTRINGEXACT, -1, "Listbox entry # 200")
  63.     MsgBox "Listbox entry found at " + Str$(t&)
  64. End Sub
  65. Private Sub Command3_Click()
  66. Dim sequence(RNDSEARCH) As String
  67. Dim si As SYSTEMTIME
  68. Dim starttime As FILETIME
  69. Dim endtime As FILETIME
  70. Dim search1time&
  71. Dim search2time&
  72. Dim x%, searchcount%
  73. Dim maxlistentry%
  74. Dim dl&
  75. Screen.MousePointer = 11
  76. ' Load the array with a sequence
  77. maxlistentry% = List1.ListCount ' It's faster to use a variable than a property
  78. For x% = 1 To RNDSEARCH
  79.     sequence(x%) = "Listbox entry #" & Str$(Int(Rnd * maxlistentry%))
  80. Next x%
  81. ' Now search using code
  82. GetSystemTime si
  83. dl& = SystemTimeToFileTime(si, starttime)
  84. For searchcount% = 1 To RNDSEARCH
  85.     For x% = 1 To maxlistentry%
  86.         If List1.List(x%) = sequence(searchcount%) Then Exit For
  87.     Next x%
  88. Next searchcount%
  89. GetSystemTime si
  90. dl& = SystemTimeToFileTime(si, endtime)
  91. ' Find the difference in time
  92. search1time = FileTimeDifference(endtime, starttime)
  93. GetSystemTime si
  94. dl& = SystemTimeToFileTime(si, starttime)
  95. For searchcount% = 1 To RNDSEARCH
  96.     dl& = SendMessageByString&(List1.hWnd, LB_FINDSTRINGEXACT, -1, sequence(searchcount%))
  97. Next searchcount%
  98. GetSystemTime si
  99. dl& = SystemTimeToFileTime(si, endtime)
  100. ' Find the difference in time
  101. search2time = FileTimeDifference(endtime, starttime)
  102. Screen.MousePointer = 0
  103. MsgBox "VB search: " & search1time & "ms API search: " & search2time & "ms"
  104. End Sub
  105.