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 / samples4 / ch02 / ch02.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-04-07  |  3.2 KB  |  106 lines

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