|
-
Dec 2nd, 2002, 04:51 PM
#1
Thread Starter
Hyperactive Member
printing numbers in ascending order (in a string)
Hi,
My code below choses 10 numbers from 1 to 10 (same number not repeated twice).
The numbers are then listed in my picturebox, but I need to sort them in ASCENDING ORDER.
Any idea how I can do this?
Thanks for any help!
Public First As Integer, Second As Integer, Third As Integer, _
Fourth As Integer, Fifth As Integer, Sixth As Integer, _
Seventh As Integer, Eigth As Integer, Ninth As Integer, _
Tenth As Integer
Private Sub Command1_Click()
Dim Numbers As New Collection, a As Integer
Dim result As New Collection, temp As String
Randomize
Randomize
For a = 1 To 10
Numbers.Add a
Next a
Do While Numbers.Count
a = Int(Rnd * Numbers.Count) + 1
result.Add Numbers(a)
Numbers.Remove a
Loop
First = result(1)
Second = result(2)
Third = result(3)
Fourth = result(4)
Fifth = result(5)
Sixth = result(6)
Seventh = result(7)
Eigth = result(8)
Ninth = result(9)
Tenth = result(10)
Picture1.Cls
Picture1.Print First & " " & Second & " " & Third & " " & _
Fourth & " " & Fifth & " " & Sixth & " " & _
" " & Seventh & " " & Eigth & " " & Ninth & " " & Tenth
End Sub
-
Dec 3rd, 2002, 05:38 AM
#2
Frenzied Member
Look up sorting in this forum.
There are many ways you can sort, each have different techniques and are suitable for different sizes of arrays. Basically you want to find the largest item, then find the next, and then the next - so its all a matter of comparisons.
-
Dec 3rd, 2002, 07:37 AM
#3
Hyperactive Member
i think i have a problem with trying to figure out why people are trying to do something and spend less time trying to answer their question heh...
but then i didnt understand the question so i ended up trying to figure out why again.
why not just randomize 1 - 10 when your originally adding to the collection. and why use a collection instead of an integer array?
What are you trying to sort by? the collections index or the value?
-
Dec 3rd, 2002, 07:47 AM
#4
Frenzied Member
Originally posted by Eyes.Only
i think i have a problem with trying to figure out why people are trying to do something
Consider it a valuable lesson, and well worth the effort!
a) You will phrase your questions better when you need something (and not just on this forum).
And b) When writing programs for clients / bosses / users etc they will also phrase their requirements in a non-logical manner, and you will need to translate what they asked for into what they actualy need.
-
Dec 3rd, 2002, 08:07 AM
#5
Hyperactive Member
haha very true
-
Dec 4th, 2002, 04:54 AM
#6
Hyperactive Member
hi,
after added numbers try this
for i=1 to 10
for j=i+1 to 10
if result(i)>result(j) then
tmp=result(i)
result(i)=result(j)
result(j)=tmp
end if
next
next.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|