|
-
Jul 18th, 2005, 04:08 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] search listbox
can anybody show me how to do a binary search in a sorted listbox ?
thanks.
-
Jul 18th, 2005, 04:18 PM
#2
Re: search listbox
Not sure if this is Binary, but it is the quickest way to search it.
VB Code:
Option Explicit
Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const CB_FINDSTRINGEXACT = &H158
Private Const LB_FINDSTRINGEXACT = &H1A2
Public newitem As String
Sub searchlist()
Dim lngRetVal As Long
lngRetVal = SendMessageString(List1.hWnd, _
LB_FINDSTRINGEXACT, -1&, _
newitem)
If lngRetVal = -1& Then
List1.AddItem newitem
Else
List1.ItemData(lngRetVal) = List1.ItemData(lngRetVal) + 1
MsgBox List1.ItemData(lngRetVal)
' It's already in the list and lngRetVal is the listindex
End If
-
Jul 18th, 2005, 04:30 PM
#3
Thread Starter
Hyperactive Member
Re: search listbox
thanks but its not what i am after.
i am doing a listbox usercontrol and i want to do a sorted sub so when i add a new item i need to know which index to put it so i know the binary search will be the quickest but i dont know how to do it.
thanks.
-
Jul 18th, 2005, 05:02 PM
#4
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|