Hi everyone, I'm back after 4 months without Dani!

Today i just came across a problem about programming. The application I'm doing requires me to "enter the size of an array in a TEXTBOX, then click a button, a list of random number would show up, then re-arrange from Lowest to Highest".

For ex, i enter "5" in the TextBox, then an array or list of 5 random number will show up vertically on the ListBox. I already got this part done. Now the thing is, I have to make a For...Next statement to rearrange them from Lowest to Highest.

Can somebody please teach me how to do this?

4
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by cellus205

Here's my code:

Dim intnumberenter As Integer = Val(Me.txtenter.Text)

Dim intallrandomnumbers(intnumberenter) As Integer

Dim intonerandom As Integer

Randomize() 'Randomize 10 numbers from 1 to 99

Dim intnumber As Integer

For intnumber = 1 To intnumberenter

intonerandom = Int(99 * Rnd()) + 1

intallrandomnumbers(intnumber - 1) = intonerandom 'Add the number to the array

Next intnumber

Me.lstarray.Items.Clear()

Me.lstarray.Items.Add("Index" & Space(13) & "Random Numbers" & Space(13) & "Lowest To Highest")

For intnumber = 1 To intnumberenter

Me.lstarray.Items.Add((intnumber - 1) & Space(32) & intallrandomnumbers(intnumber - 1))

Next intnumber

Dim intMin As Integer

intMin = intallrandomnumbers(0)

Dim intNum As Integer

For intNum = 0 To Val(intallrandomnumbers(intnumberenter))

If intallrandomnumbers(intNum) < intMin Then

intMin = intallrandomnumbers(intNum)

End If

Next intNum

Me.lbla.Text = intMin

What i intend to do is looping for the min number, then take it off the array, and add it to a new array, so that after all the numbers of the original array are looped, the new array would contain numbers from lowest to highest. (but now, my method of finding the lowest number does not work. And I dont know what error i make. So please help me.) Thank you for your time and consideration!

how to create a program that will allow you to choose a number and show the numbers inside the label once the display button is clicked. the number should arranged from lowest to highest.

Just sort the list.

list.sorttype = ascending
list.sort()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.