So, the code that I have figured out so far is: The names can be entered in a listbox, and then I put them into an array. Then I have a piece of code that randomizes the array (I tested it to make sure it displayed a random order of names).
The problem that I am having now is figuring out how to use the for next loop to cycle through the array. For example, I don't know how this would work exactly, but I need the loop to put lstNames(0) in lblGroup1.text..lstNames(1) in lblGroup2.text...lstNames(2) in lblGroup3.text...lstNames(3) in lblGroup4.text....lstNames(4) in lblGroup1.text....and so on until the loop reaches the end of the array and all of the names are evenly distributed in one of the four groups and displayed in their respective groups.
I've tried different for/next and for/each loops. Do I create an array for each of the four groups and then display the array in the label? If so, how would I do that?
I have been trying to figure this out all day, there has to be something that I am just totally missing/thinking its harder than it is...so sorry if this question is dumb! Any information would be greatly appreciated.
Here is the code that I have so far:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Create array that holds all student's names..goes through listbox and adds them to array
Dim strNameArray() As String
ReDim strNameArray(lstNames.Items.Count - 1)
lstNames.Items.CopyTo(strNameArray, 0)
'Randomizes the array
Dim random As New Random()
Dim max_index As Integer = random.Next(0, lstNames.Items.Count() - 1)
Dim rnd As New Random
For i As Integer = 0 To max_index - 1
' Pick an item for position i.
Dim j As Integer = rnd.Next(i, max_index + 1)
' Swap them.
Dim temp As String = strNameArray(i)
strNameArray(i) = strNameArray(j)
strNameArray(j) = temp
Next i
'>>>>>>>>>>>>>>>>>This is where I am stuck<<<<<<<<<<<<<<<<<<<<<<<<<
'loop through array and put each name in a group
'Dim intMAX_SUB As Integer = lstNames.Items.Count() - 1
'Dim intCount As Integer
'For intCount = 0 To intMAX_SUB Step 1
' lblGroup1.Text = strNameArray(intCount)
'Next
'Display the group results in the respective label
End Sub
End Class

New Topic/Question
Reply



MultiQuote




|