How can I sort Listboxes using (Random)

  • Thread starter Thread starter Gary Simpson
  • Start date Start date
G

Gary Simpson

Guest
Hi Good People.

I am trying to write code for a number generator/picker using List boxes, On My form I have...

  1. Listbox1
  2. Listbox2
  3. Listbox3
  4. Listbox4
  5. Listbox5
  6. Listbox6
  7. 1 Button called (cmdMainGenerate)
  8. cmdGenerate1.PerformClick()
  9. cmdGenerate2.PerformClick()
  10. cmdGenerate3.PerformClick()
  11. cmdGenerate4.PerformClick()
  12. cmdGenerate5.PerformClick()
  13. cmdGenerate6.PerformClick()
  1. I have used "Random" in my code to Generate one number for each of the six Listboxes
  2. When I click cmdMainGenerate, This in turn Performs Clicks on all other Buttons
  3. Then Numbers a generated, into all the Listboxes, But The number are not in sequence etc (46, 39, 9, 23, 39, 53)
  4. Does anyone know how I can make these numbers to be in order from left to right.

The Code I have is below...

Option Strict On
Option Explicit On
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub cmdGenerate1_Click(sender As Object, e As EventArgs) Handles cmdGenerate1.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox1.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox1.Items.Add(MyRand.ToString())
End Sub


Private Sub cmdGenerate2_Click(sender As Object, e As EventArgs) Handles cmdGenerate2.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox2.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox2.Items.Add(MyRand.ToString())
End Sub

Private Sub cmdGenerate3_Click(sender As Object, e As EventArgs) Handles cmdGenerate3.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox3.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox3.Items.Add(MyRand.ToString())
End Sub

Private Sub cmdGenerate4_Click(sender As Object, e As EventArgs) Handles cmdGenerate4.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox4.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox4.Items.Add(MyRand.ToString())
End Sub

Private Sub cmdGenerate5_Click(sender As Object, e As EventArgs) Handles cmdGenerate5.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox5.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox5.Items.Add(MyRand.ToString())
End Sub

Private Sub cmdGenerate6_Click(sender As Object, e As EventArgs) Handles cmdGenerate6.Click
Dim Generator As New Random
Dim MyRand As Integer
ListBox6.Items.Clear()

MyRand = Generator.Next(1, 59)
ListBox6.Items.Add(MyRand.ToString())
End Sub

Private Sub cmdMainGenerate_Click(sender As Object, e As EventArgs) Handles cmdMainGenerate.Click
cmdGenerate1.PerformClick()
cmdGenerate2.PerformClick()
cmdGenerate3.PerformClick()
cmdGenerate4.PerformClick()
cmdGenerate5.PerformClick()
cmdGenerate6.PerformClick()

'NumberOrder()
End Sub

'Private Function NumberOrder()
' Dim Val1 As Integer = Val(ListBox1.Items.ToString)
' Dim Val2 As Integer = Val(ListBox2.Items.ToString)
' Dim Val3 As Integer = Val(ListBox3.Items.ToString)
' Dim Val4 As Integer = Val(ListBox4.Items.ToString)
' Dim Val5 As Integer = Val(ListBox5.Items.ToString)
' Dim Val6 As Integer = Val(ListBox6.Items.ToString)

' If Val(Val1.ToString < Val(Val2.ToString)) Then
' TextBox1.Text = Val1.ToString
' Else
' TextBox1.Text = Val2.ToString
' End If

'End Function



End Class

1485318.png




Gary Simpson

Continue reading...
 
Back
Top