Sorting

General support topics
Post Reply
Razor McGoo
Posts: 4
Joined: Sun Mar 29, 2020 7:44 pm

Sorting

Post by Razor McGoo » Thu Apr 23, 2020 8:24 pm

Could I see an example of how to use the sort function with a 2 dimensional array. I'm just getting syntax errors.

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Sorting

Post by kibernetik » Fri Apr 24, 2020 6:06 am

The example:

Code: Select all

dim m(3 1) = "eight" "three" "six" "one",8 3 6 1

option tab 6
print "Table:"
print
for row=0 to 3
  for col=0 to 1
    print m(row col),
  next
  print
next
print

'sort table using 2nd column
dim sv()
sv = sort up m,1

print "1st column sorted up by 2nd column:"
print
for i=0 to 3
  row = sv(i)
  print m(row 0)
next
Its output:

Code: Select all

Table:

eight  8    
three  3    
six    6    
one    1    

1st column sorted up by 2nd column:

one
three
six
eight

Razor McGoo
Posts: 4
Joined: Sun Mar 29, 2020 7:44 pm

Re: Sorting

Post by Razor McGoo » Fri Apr 24, 2020 6:22 am

Thanks that was huge help

Post Reply