The LB_FINDSTRINGEXACT Message used with the SendMessage API will quickly tell you if an Item is already in the List, ie.
Code: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_FINDSTRINGEXACT = &H1A2 Private Sub Command1_Click() 'Clear the List and Start the Timer List1.Clear Timer1.Interval = 100 End Sub Private Sub Timer1_Timer() 'Generate a Number Between 0 And 9 Dim sChar As String sChar = Chr(Int(Rnd * 10) + 48) 'Only Add it to the List if it's not already there. If SendMessage(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal sChar) < 0 Then List1.AddItem sChar End If End Sub




Reply With Quote