how to compare list

P

Pascal

Hello
How to compare two list to know if they match?
LesNbresAverifier and MesNbres

On a form, I put 20 labels, 10 of them have have theit text property filled
from a list containing numbers:
Dim MesNbres As List(Of Object)
Dim i As Short = 0
MesNbres = utility.GenArrayNbres(min, max, RdBtnDecim.Checked, 10, True)
For Each C As MonLabel In TableLayoutPanel4.Controls
C.LblText = FormatNumber(MesNbres(i), 0, TriState.False, TriState.False,
TriState.True)
i += 1
Next
The content of these labels will be deposited by a DragDrop in the
remaining 10 labels. And it should comply with an ascending (or descending)
order.
I know how to order my list:
MesNbres.Sort()
Now I would like to compare this ordered list with the contents of the
10 labels who received the drop to see if they contained in ascending order
my 10 numbers. How do I do?
1) Do I create a list from labels.text then compare this list with
another (MesNbres)
Which method can I use to compare the two lists that will return
a false in the case of a difference between the two lists?

Here is the code to built the List from numbers in the labels
Private Function LblTxtToList()

Dim i As Integer

For Each C As MonLabel In TableLayoutPanel5.Controls

If C.LblText <> "" Then

LesNbresAverifier.Add(C.LblText)

i += 1

Else

Return MsgBox("You did'nt fill all the labels.",
MsgBoxStyle.Exclamation, "Attention")

C.Focus()

Exit Function

End If

Next

Return LesNbresAverifier

End Function


thank you


--
http://www.scalpa.info
http://scalpa-production.blogspot.com/






































http://www.scalpa.info
http://scalpa98.blogspot.com/
 
C

Cor Ligthert[MVP]

Pascal,

If you want to compare values in 2 list, then you normally have to use a
nested foreach

For Each x in y
for Each a in b
do your compare
next
next

Don't be afraid of those 100 time looping, I am not able to write how little
time a loop takes.

Cor
 
P

Pascal

I did this and it seems to work, thanks
Private Function ListsAreEquals(ByVal List1 As List(Of Object), ByVal List2
As List(Of Object)) As Boolean

'D'abord, v,rifier que les lists ont le m^me nombres d',lSments

Dim flag As Boolean

If List1.Count = List2.Count Then

Dim i As Integer

flag = True

'On parcourt tous les ,l,ments de la liste

For i = 0 To List1.Count - 1

If List1.Item(i).ToString = List2.Item(i).ToString Then

'On continue

Else

'Les ,l,ments sont diff,rents

flag = False

'pas la peine d'aller plus loin

Exit For

End If

Next i

Return flag

Else

flag = False

'MsgBox("Les listes ne contiennent pas le m^me nombre d',l,ments",
MsgBoxStyle.Exclamation, "Erreur")

Return flag

End If

End Function


--
http://www.scalpa.info
http://scalpa-production.blogspot.com/






































http://www.scalpa.info
http://scalpa98.blogspot.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top