AlexAlexon
11-17-2007, 02:45 AM
This is Lottery program which generate random numbers, but output is not sorted. How to sort numbers in asceding order?
This is VBA Express.
Public Class ltaForm
Private Sub GetNumbersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetNumbersToolStripMenuItem.Click
Dim intForLoopCtr As Integer = 0
Dim blnFullSetComplete As Boolean = False
Dim intRndNo As Integer = 0
Dim strDisplayString As String = ""
Dim intNoOfValidPics As Integer = 0
Dim aintLotteryArray(10) As Array
Dim intNumberCount As Integer = 0
Dim strTestString As String = "_"
If txtFullSet.Text = "" Then
MessageBox.Show("You must specify how many numbers " & _
"make up a full set.")
Return
End If
If IsNumeric(txtFullSet.Text) = False Then
MessageBox.Show("You must specify numeric input when " & _
"specifying how many numbers make up a full set.")
Return
End If
For intForLoopCtr = 1 To CInt(txtNoPics.Text)
Do Until blnFullSetComplete = True
Randomize()
intRndNo = _
FormatNumber(Int((txtNoRange.Text * Rnd()) + 1))
If InStr(strTestString, _
Convert.ToString("_" & intRndNo & "_")) = 0 Then
strDisplayString = strDisplayString & " " & _
intRndNo & ControlChars.Tab
intNoOfValidPics = intNoOfValidPics + 1
strTestString = strTestString & intRndNo & "_"
End If
If intNoOfValidPics = Int32.Parse(txtFullSet.Text) Then
blnFullSetComplete = True
strDisplayString = strDisplayString & _
ControlChars.NewLine & ControlChars.NewLine
strTestString = "_"
End If
Loop
blnFullSetComplete = False
intNoOfValidPics = 0
Next
txtOutput.Text = strDisplayString
GetNumbersToolStripMenuItem.Enabled = False
ClearToolStripMenuItem.Enabled = True
End Sub
This is VBA Express.
Public Class ltaForm
Private Sub GetNumbersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetNumbersToolStripMenuItem.Click
Dim intForLoopCtr As Integer = 0
Dim blnFullSetComplete As Boolean = False
Dim intRndNo As Integer = 0
Dim strDisplayString As String = ""
Dim intNoOfValidPics As Integer = 0
Dim aintLotteryArray(10) As Array
Dim intNumberCount As Integer = 0
Dim strTestString As String = "_"
If txtFullSet.Text = "" Then
MessageBox.Show("You must specify how many numbers " & _
"make up a full set.")
Return
End If
If IsNumeric(txtFullSet.Text) = False Then
MessageBox.Show("You must specify numeric input when " & _
"specifying how many numbers make up a full set.")
Return
End If
For intForLoopCtr = 1 To CInt(txtNoPics.Text)
Do Until blnFullSetComplete = True
Randomize()
intRndNo = _
FormatNumber(Int((txtNoRange.Text * Rnd()) + 1))
If InStr(strTestString, _
Convert.ToString("_" & intRndNo & "_")) = 0 Then
strDisplayString = strDisplayString & " " & _
intRndNo & ControlChars.Tab
intNoOfValidPics = intNoOfValidPics + 1
strTestString = strTestString & intRndNo & "_"
End If
If intNoOfValidPics = Int32.Parse(txtFullSet.Text) Then
blnFullSetComplete = True
strDisplayString = strDisplayString & _
ControlChars.NewLine & ControlChars.NewLine
strTestString = "_"
End If
Loop
blnFullSetComplete = False
intNoOfValidPics = 0
Next
txtOutput.Text = strDisplayString
GetNumbersToolStripMenuItem.Enabled = False
ClearToolStripMenuItem.Enabled = True
End Sub