Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,237 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,257 people online right now. Registration is fast and FREE... Join Now!




Randomly assign data from array into list boxes

 
Reply to this topicStart new topic

Randomly assign data from array into list boxes, Visual Basic .NET 2008 Express

south73paw
12 Oct, 2008 - 07:11 PM
Post #1

New D.I.C Head
*

Joined: 6 Oct, 2008
Posts: 11


My Contributions
Hi, I'm creating a program that has the following features:

1. Load names (1 per line) from a text file into a list box on a button click event - DONE
2. Ability to add or delete names from this list box - DONE
3. Re-save the contents of the list box to the original text file - DONE
4. Load the contents of the list box into an array (just doing this from a click event) - DONE
5. Randomly assign each name in the array to one of two further list boxes (or they could be text boxes) - THIS IS WHY I COME UNSTUCK!

How do I do step 5?

I can create random numbers easily enough, but I want the names in the array (which are likely to be in alphabetical order from the original list box elsewhere in the form) to be distributed into other controls. Think of it like this:

1. The user has the ability to manipulate names in the array by the add/delete options in the original list box
2. Once the up-to-date list of names are in the array, the names can then be distributed into 2 teams

The following code just gives be String[] Array repeated 5 times in one list box only:
CODE

  'Variable for random number assign to each item in the array
        Dim intRandomNumber As Integer
        'Initiate the random number generator
        Randomize()
        'General random numbers
        'equivalent to the maximum number of names stored in the array
        intRandomNumber = (Int(UBound(Names) - LBound(Names) + 1) * Rnd() + LBound(Names))
        'Assign each name in the array with a random number
        For i = 0 To UBound(Names) - 1
            ReDim Preserve Names(i + 1)
            Names(i) = intRandomNumber
            If intRandomNumber = 1 Or 3 Or 5 Or 7 Or 9 Or 11 Then
                lstTeamOne.Items.Add(Names)
            Else
                lstTeamTwo.Items.Add(Names)
            End If
        Next i


Thanks,

Any help would be greatly appreciated
User is offlineProfile CardPM
+Quote Post

south73paw
RE: Randomly Assign Data From Array Into List Boxes
12 Oct, 2008 - 08:23 PM
Post #2

New D.I.C Head
*

Joined: 6 Oct, 2008
Posts: 11


My Contributions
Sorry, I'll add the code with the correct tags this time!

CODE
      
'Variable for random number assign to each item in the array
        Dim intRandomNumber As Integer
        'Initiate the random number generator
        Randomize()
        'Generate random numbers
        'equivalent to the maximum number of names stored in the array
        intRandomNumber = (Int(UBound(Names) - LBound(Names) + 1) * Rnd() + LBound(Names))
        'Assign each name in the array with a random number
        For i = 0 To UBound(Names) - 1
            Names(i) = intRandomNumber
        Next i

        If intRandomNumber = 1 Or 3 Or 5 Or 7 Or 9 Or 11 Then
            lstTeamOne.Items.Add(Names)
        Else
            lstTeamTwo.Items.Add(Names)
        End If

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:36AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month