Aargh ! I watched the code (the clue is not enough for a beginner like me)
I have not moved an inch!
So I explain the goal...
I wonder if you could help me : i am trying to build a software for my
pupils (primary school) in which I will use random generated numbers
(integers or decimals) For example i need ten numbers appearing in ten
different labels, and by dragging and dropping them in 10 other labels, they
have to sort them in ascending or descending order. So when they click on a
button to verify their job, i need to verify if the numbers are from the set
generated by the computer (that's for avoiding the cheat
upils could have
written ten simple numbers, from 1 to 11 by example, in the labels before
validating their job!)and if they are in the correct order.
The interface works well, drag and drop etc. too. But the generation of 10
random and unique numbers , poses a problem.
I tried this to generate unique or not numbers without success, what's wrong
here?
thanks for help
pascal
<pre>Public Shared Function GenArrayNbres(ByVal Lower As Long, ByVal Upper
As Long, _
Optional ByVal HowMany As Integer = 1, _
Optional ByVal Unique As Boolean = True) As Object
Dim c As New Collection
Dim list As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim ajout As Boolean = True
If HowMany < ((Upper + 1) - (Lower - 1)) Then
Try
ReDim list(HowMany - 1) 'redimensinner le tableau en
fonction de la quantité de nombres à obtenir
list(0) = GenNombre(Lower, Upper) 'initialise le tableau
For i As Integer = 1 To HowMany - 1
If Unique Then ' si pas de doublon
'ReDim Preserve list(i) 'on redimensionne le tableau
list(i) = GenNombre(Lower, Upper) ' on tire un
nombre
Do 'on compare l'élément en cours avec chaque
élément du tableau
For j As Integer = 0 To i - 1 'list.Length - 2
If list(i) = list(j) Then 'l'élément existe
déjà
Unique = False
Exit For 'on sort de la boucle de test
End If
Next
list(i) = GenNombre(Lower, Upper) 'on tire à
nouveau
Loop Until Unique = True
Else
list(i) = GenNombre(Lower, Upper)
End If
Next
Catch ex As ApplicationException
End Try
Else
MsgBox("Attention aux valeurs choisies" & Chr(13) &
"max-min > Nbres", MsgBoxStyle.Exclamation, "Erreur")
End If
GenArrayNbres = list
End Function</pre>