You can use SendMessage api to check whether or not item already exists:
Regarding collection vs array - this could be a good topic for another thread.Code:Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Const LB_FINDSTRING = &H18F Private Const LB_FINDSTRINGEXACT = &H1A2 Private Function FindItem(lst As ListBox, strText As String) As Long Dim iIndex As Integer iIndex = SendMessage(lst.hwnd, LB_FINDSTRINGEXACT, -1, ByVal strText) FindItem = iIndex End Function 'usage: If FindItem(List1, "whatever") = -1 Then List1.AddItem = "whatever" End If
While arrays are faster collections have key property so it could be simpler to get specific item.




Reply With Quote