Post by billknott on Jul 16, 2022 2:56:19 GMT -5
Is there some limitation of the SORT command?
I have a double dimensioned array with 8 second elements any one of which needs variously to be sorted during program operation.
The array first element value (rows) may at times be shorter than the number of second elements (columns).
If a sort is done using a sort key value greater than the number of rows, then it crashes.
If the sort key used is less than the number of rows, then it works
If the number of rows is greater than the number of columns then it works using any valid sort key.
The error message when it crashes says "out of range for array$("
This appears to defy logic as the key used for the sort is related to the second array column element but
the error handler appears to be focused on the first array row element.
Am I missing something here? I have played around with this for a while but I can't see what is wrong!
To illustrate I have simplified the code down to the essentials to demonstrate what is happening.
I have a double dimensioned array with 8 second elements any one of which needs variously to be sorted during program operation.
The array first element value (rows) may at times be shorter than the number of second elements (columns).
If a sort is done using a sort key value greater than the number of rows, then it crashes.
If the sort key used is less than the number of rows, then it works
If the number of rows is greater than the number of columns then it works using any valid sort key.
The error message when it crashes says "out of range for array$("
This appears to defy logic as the key used for the sort is related to the second array column element but
the error handler appears to be focused on the first array row element.
Am I missing something here? I have played around with this for a while but I can't see what is wrong!
To illustrate I have simplified the code down to the essentials to demonstrate what is happening.
LastRecordNumber = 5 'change to experiment with LastRecordNumber lower than second array element
dim List$(LastRecordNumber,8)
gosub [ArrayData]
for x = 0 to LastRecordNumber
for y = 0 to 8
print List$(x,y ) 'all good for all array element values
next
next
print:print
z = 2 'value for second element of array. This works fine for all z values up to LastRecordNumber
for n = 1 to LastRecordNumber
print "this is List$(";n;",";z;") - " + List$(n,z) 'works for all z values up to 8
next
print:print "start first sort"
sort List$(),LastRecordNumber, 1, z 'works for all z values up to LastRecordNumber , crashes with any z value above LastRecordNumber lower than second array element
for n = 1 to LastRecordNumber
print List$(n,z)
next
print:print "start second sort"
sort List$(), 1, LastRecordNumber,z 'works for all z values up to LastRecordNumber , crashes with any z value above LastRecordNumber lower than second array element
for n = 1 to LastRecordNumber
print List$(n,z)
next
print:print
wait
[ArrayData]
List$(0,0)="Supplier":List$(0,1)="Finish Type":List$(0,2)="Finish Colour":List$(0,3)="Mx":List$(0,4)="Board"
List$(0,5)="Match":List$(0,6)="Panelcode":List$(0,7)="Available":List$(0,8)="0"
List$(1,0)="PDM Distributors Ltd":List$(1,1)="Foil":List$(1,2)="Buttermilk":List$(1,3)="1.5"
List$(1,4)="U108 ST9":List$(1,5)="Exact":List$(1,6)="2":List$(1,7)="Yes":List$(1,8)="1"
List$(2,0)="Mason Distribution Ltd":List$(2,1)="Urbani":List$(2,2)="Light Grey":List$(2,3)="1.5"
List$(2,4)="U732":List$(2,5)="Close":List$(2,6)="1":List$(2,7)="Yes":List$(2,8)="2"
List$(3,0)="Panel Products Ltd":List$(3,1)="Vinyl":List$(3,2)="Grey Onyx Matt":List$(3,3)="1.2"
List$(3,4)="U960 ST9":List$(3,5)="Exact":List$(3,6)="1":List$(3,7)="Yes":List$(3,8)="3"
List$(4,0)="Bridgeton & Son Ltd":List$(4,1)="Laquer":List$(4,2)="red alder":List$(4,3)="1.6"
List$(4,4)="U700 ST8":List$(4,5)="Good":List$(4,6)="4":List$(4,7)="reset":List$(4,8)="4"
List$(5,0)="A. Brown & Sons":List$(5,1)="Vinyl":List$(5,2)="Grained Ivory":List$(5,3)="1"
List$(5,4)="U104 ST27":List$(5,5)="Exact":List$(5,6)="3":List$(5,7)="Yes":List$(5,8)="5"
return