samedi 6 mai 2017

Visual basic (.net) > randomize listbox picks (unique)

I just want to make randomizer program. It will be used to pick tournament pairs (like f.e. UEFA Champions League quaterfinal pairs)

GUI Screen: http://ift.tt/2pRH2hE

I have trouble with this.. When I tried to make picker, it works well > from listbox 1 (left side) to listbox2 (50% of listbox1 items), listbox3 (50% of listbox1 items).. (left side) but these picks aren't unique. There are some duplicates as you can see on image (2nd listbox 2x noob).

Part of my code:

Private Sub RandomiseListBox()
    Dim count As Integer = CarbonFiberListBox1.Items.Count
    Dim countt As Integer
    'countt = count / 2
    Dim item As String
    Dim itemz As New List(Of String)()
    Dim repeat As New List(Of String)()
    Dim aa, bb As Integer


    If Not count = 0 And ((count Mod 2) = 0) Then
        CarbonFiberListBox2.Items.Clear()
        CarbonFiberListBox3.Items.Clear()

        For index As Integer = 0 To countt - 1 Step 1
            item = Me.CarbonFiberListBox1.Items(Me.randomiser.Next(index, count))
            itemz.Add(item)
            'Me.CarbonFiberListBox1.Items.Remove(item)
            'Me.CarbonFiberListBox1.Items.Insert(index, item)
            Me.CarbonFiberListBox2.Items.Insert(index, item)
        Next index

        For index As Integer = 0 To countt - 1 Step 1
            For aa = 0 To bb = 999
                item = Me.CarbonFiberListBox1.Items(Me.randomiser.Next(index, count))
                If Not (itemz.Contains(item)) And Not (repeat.Contains(item)) Then
                    repeat.Add(item)
                    'Me.CarbonFiberListBox1.Items.Remove(item)
                    'Me.CarbonFiberListBox1.Items.Insert(index, item)
                    Me.CarbonFiberListBox3.Items.Insert(index, item)
                End If
            Next
        Next index

        'For index As Integer = 0 To countt - 1 Step 1

        'Next index
    ElseIf count > 0 Then
        'CarbonFiberButton4.Text = "ODD PARTICIPANTS!"
    Else
    End If
End Sub

Can I get help? I think it is so easy.




Aucun commentaire:

Enregistrer un commentaire