Hello. I am new to programming and I am trying to find a way to sort an array of numbers. For Example, if I have 30 textboxes with a number inside, I think i could insert the numbers to this array using a For...Next statement. But then, I would like to sort the numbers once they are in the array so I could then put them into another set of textboxes(top 10). I could also do this using a For...Next statement, but sorting the array is what I need help with. Any help will be greately appreciate it. Thanks.

u can use sequential/bubble/quick sort techniques. here is one of the logic for sorting

Dim a(5) as Integer
Dim i as Integer
Dim j as Integer

a(0) = 10
a(1) = 9
a(2) = 13
a(3) = 45
a(4) = 7

For i = 0 to 4
    For j = i + 1 to 4
        If a(i) > a(j) Then
'            swap the number in those two locations
'            For Eg: if x = 10 and y = 9 then
'                x            y
'               10           9
'             Since 10 > 9 we swap x  and  y
'                x = x + y   =>  x = 10 + 9 = 19
'                y = x - y    =>  y = 19 - 9 = 10 => y = 10
'                x = x - y    =>  x = 19 - 10 = 9 => x = 9
            a(i) = a(i) + a(j)
            a(j) = a(i) - a(j)
            a(i) = a(i) - a(j)
        End If
    Next j
Next i

'Now the array would hold the values in ascending order
'To sort in descending order just make the following change
'If a(i) < a(j) Then

hope this answers ur question. If ur need is something else other than this then plz let know.

hey,
do you know the different types of number array sorting codes (highest-lowest or lowest-highest) for visual basic??
i have learnt bubble, selection and insertion. are there any more?? if so, please do explain.
thank you :D

hey,
do you know the different types of number array sorting codes (highest-lowest or lowest-highest) for visual basic??
i have learnt bubble, selection and insertion. are there any more?? if so, please do explain.
thank you :D

. . . Can you help me? can you give me a hint in bubble,selection and insertation sort? or just give me the code in vb? thx .

This article has been dead for over six months. Start a new discussion instead.