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...
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
Gary Simpson
Continue reading...
I am trying to write code for a number generator/picker using List boxes, On My form I have...
- Listbox1
- Listbox2
- Listbox3
- Listbox4
- Listbox5
- Listbox6
- 1 Button called (cmdMainGenerate)
- cmdGenerate1.PerformClick()
- cmdGenerate2.PerformClick()
- cmdGenerate3.PerformClick()
- cmdGenerate4.PerformClick()
- cmdGenerate5.PerformClick()
- cmdGenerate6.PerformClick()
- I have used "Random" in my code to Generate one number for each of the six Listboxes
- When I click cmdMainGenerate, This in turn Performs Clicks on all other Buttons
- Then Numbers a generated, into all the Listboxes, But The number are not in sequence etc (46, 39, 9, 23, 39, 53)
- 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
Gary Simpson
Continue reading...