|
-
Nov 10th, 2002, 10:32 AM
#1
Thread Starter
Member
Making sure listbox contents are not the same
I have a number of different entries in a listbox (they vary from 1 to 1001, so making a basic (set) IF statement will not work. The entries must not be the same. If they are the same, a messagebox will show saying so.
How can i do this?
Thanks
Dave
-
Nov 10th, 2002, 10:39 AM
#2
Well ...
To quickly catch duplicates, you can set the Sorted property of the listbox to True. However I still think you will need to run a loop to automatically remove duplicates.
.
-
Nov 10th, 2002, 10:47 AM
#3
PowerPoster
Well
Filter duplicates without API :
VB Code:
Dim i As Long, J As Long
With .cboPending
For i = 0 To .ListCount - 1
For J = .ListCount To (i + 1) Step -1
If .LIST(J) = .LIST(i) Then
.RemoveItem J
End If
Next
End With
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Nov 10th, 2002, 10:48 AM
#4
Frenzied Member
Irrespective of the number of entries, you are going to have to llop through the contents of both listboxes to find out if there's a match.
VB Code:
Private Sub Command1_Click()
Dim FirstBox As Integer
Dim SeconBox As Integer
Dim bMatch As Boolean
bMatch = False
For FirstBox = 0 To List1.ListCount - 1
For SeconBox = 0 To List2.ListCount - 1
If LCase(List1.List(FirstBox)) = LCase(List2.List(SeconBox)) Then bMatch = True
Next
Next
If bMatch Then
MsgBox "Item exists"
Else
MsgBox "No matches in the lists"
End If
End Sub
Mega.
"If at first you don't succeed, then skydiving is not for you"
-
Nov 10th, 2002, 10:49 AM
#5
Frenzied Member
GODDAM. Beaten again
"If at first you don't succeed, then skydiving is not for you"
-
Nov 10th, 2002, 10:50 AM
#6
Frenzied Member
Actually, forget what I said, I thought you were comparing entries in 2 list boxes.
Never mind, I will leave my code for those who want to do that 
Mega.
"If at first you don't succeed, then skydiving is not for you"
-
Nov 10th, 2002, 10:59 AM
#7
Mega_Man: You don't have to loop through the entries.
VB Code:
Public 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
Public Const CB_FINDSTRING = &H14C ' For a ComboBox
Public Const LB_FINDSTRING = &H18F ' For a ListBox
Dim lngRetVal As Long
' If the value is in the list then this returns its ListIndex, otherwise it returns -1
lngRetVal = SendMessageString(MyListbox.hwnd, LB_FINDSTRING, -1&, "value to find")
-
Nov 10th, 2002, 11:49 AM
#8
PowerPoster
Well
Filter duplicates without API :
You don't have to loop through the entries.
Now he has both...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
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
|