can anybody show me how to do a binary search in a sorted listbox ?
thanks.
Printable View
can anybody show me how to do a binary search in a sorted listbox ?
thanks.
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
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.
ok, i got it.
thanks.