Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to sort names and numbers?
    text
    copied!<p>vv</p> <p>After completing my school assignment on simple array sorts I came up with this question. Say I have a textbox with a name in it. Right beside that I have a textbox with number in it. Exp <code>txtBox1 = "John Doe"</code>, <code>txtBox2 = 8</code>. Lets say I have 10 rows. that would be 20 text boxes. How could I randomly sort these by name keeping all like numbers together in sequential order. Output should look something like this. The key here is to randomly sort the names within the same number group.</p> <ul> <li>John Doe 3</li> <li>Mary Jane 3</li> <li>name 4</li> <li>name 4</li> <li>name 4</li> <li>name 5</li> <li>name 7</li> <li>name 7</li> <li>name 8</li> <li>name 8</li> </ul> <p>This is the code that I have. it is slightly different in the fact that it has 3 column of textbox and 8 rows. This randomly sort the 3 rows keeping the information together in the same row. John Doe, 3, phonenumber. and then puts the information in a mirror image of textboxs. the number represents a skill level so I need alike skill levels to play alike skill levels but randomly sorted within there skill level. Which this does not have. I cant having a 3 play a 7. I hope this makes since. Its almost as if I need a random order inside a sequencial order.</p> <pre><code>Dim ListOfValues As New List(Of List(Of String)) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.txtA1.Focus() End Sub Private Sub AddTB(row As Integer, column As Integer, start As Char) Dim tb As New TextBox Dim offset As Integer = Math.Sign(Asc(start) - 65) * (100 + tb.Width * 3) tb.Name = "txt" &amp; Chr(row + Asc(start)) &amp; column.ToString tb.Text = tb.Name tb.Location = New Point(((column - 1) * tb.Width) + offset, (row * tb.Height)) Me.Controls.Add(tb) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'this adds the data from the textboxes to the list. each row of data is a list 'inside the list. the controls collection can be indexed by control name. 'this makes it easy to access a specific control by using a naming pattern. Button1.Enabled = True For I = 0 To 7 ListOfValues.Add({Me.Controls("txt" &amp; Chr(I + 65) &amp; "1").Text, _ Me.Controls("txt" &amp; Chr(I + 65) &amp; "2").Text, _ Me.Controls("txt" &amp; Chr(I + 65) &amp; "3").Text}.ToList) Next ListOfValues = ShuffleInfo(ListOfValues) 'This fills the other textboxes with the data from the shuffled list For I = 0 To 7 Me.Controls("txt" &amp; Chr(I + 83) &amp; "1").Text = ListOfValues(I)(0) Me.Controls("txt" &amp; Chr(I + 83) &amp; "2").Text = ListOfValues(I)(1) Me.Controls("txt" &amp; Chr(I + 83) &amp; "3").Text = ListOfValues(I)(2) Next End Sub Private Function ShuffleInfo(ValuesToShuffle As List(Of List(Of String))) As List(Of List(Of String)) 'this follows the same basic routine you were using, swapping each item with a random item. Dim rand As New Random(Now.Millisecond) For counter = 0 To ValuesToShuffle.Count - 1 Dim n = rand.Next(counter + 1) Dim temp As List(Of String) = ValuesToShuffle(counter) ValuesToShuffle(counter) = ValuesToShuffle(n) ValuesToShuffle(n) = temp Next ShuffleInfo = ValuesToShuffle Button1.Enabled = False End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload