Author |
Topic: Array rows and columns (Read 252 times) |
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Array rows and columns
« Thread started on: Oct 5th, 2017, 10:56am » |
|
I am even more confused than usual (and that's saying something!). At the LB Community Forum both Rod and JohnF have replied to a query about sorting arrays by stating that the indices are specified as follows:
Code: and that therefore this code is incorrect:
Code: dim horsearray(25, 90) ' 25 columns, 90 rows
sort horsearray(), 0, 25, 58 ' sort rows 0 to 25 using column 58, which is not available! This would indeed be a good explanation for the OP's issue if it were not for one rather important factor: that's not how Liberty BASIC's arrays work! In fact, arrays are specified as follows:
Code: and therefore the code listed is correct. If in doubt, the LB Help file gives this example (I've fleshed it out slightly):
Code: dim repActivity$(5,2) ' 5 rows, 2 columns
repActivity$(1,1) = "Tom Maloney" : repActivity$(1,2) = "01-09-93"
repActivity$(2,1) = "Mary Burns" : repActivity$(2,2) = "01-10-93"
repActivity$(3,1) = "Rod Bird" : repActivity$(3,2) = "01-07-93"
repActivity$(4,1) = "John Fisher" : repActivity$(4,2) = "01-06-93"
repActivity$(5,1) = "Ed Dole" : repActivity$(5,2) = "01-08-93"
print "sort by date (column 2):"
sort repActivity$(), 1, 5, 2
for row = 1 to 5
print repActivity$(row, 1), repActivity$(row, 2)
next
print
print "sort by name (column 1):"
sort repActivity$(), 1, 5, 1
for row = 1 to 5
print repActivity$(row, 1), repActivity$(row, 2)
next This code runs correctly in both LB 4 and LBB.
So my confusion is twofold: why are two of the most knowledgeable and respected Liberty BASIC experts both giving false information, and why does the OP's code - which I believe to be perfectly correct - fail in LB 4?
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Array rows and columns
« Reply #1 on: Oct 5th, 2017, 5:37pm » |
|
on Oct 5th, 2017, 10:56am, Richard Russell wrote:I am even more confused than usual |
|
Have I entered some alternative dimension or what? Now Chris Iverson - another extremely experienced and knowledgeable Liberty BASIC programmer - has added his voice to that of Rod and JohnF and is also claiming that arrays are declared like this:
Code: But I remain convinced this is wrong. Here is a working example based on the OP's description - well, working in LBB at least:
Code: dim horsearray(25, 90) ' 25 rows, 90 columns
for horse = 1 to 25 ' the horse is the row
for info = 1 to 90 ' the piece of info about the horse is the column
horsearray(horse, info) = rnd(1)
next info
next horse
sort horsearray(), 1, 25, 58 ' this is the sort the OP wants to do
for horse = 1 to 25
print horsearray(horse, 58)
next It doesn't work in LB4, but swapping the row and column indices results in it not working in either LB or LBB!
Richard.
|
|
|
|
Cor
New Member
member is offline
Gender:
Posts: 8
|
|
Re: Array rows and columns
« Reply #2 on: Oct 10th, 2017, 8:19pm » |
|
It's strange though, when you put the print loop before the sort statement, it shows the correct data at column 58 for 25 rows.
A slight error in LB?? Or in the definition of the sort statement in the help file??
Cor
|
« Last Edit: Oct 10th, 2017, 8:22pm by Cor » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Array rows and columns
« Reply #3 on: Oct 10th, 2017, 9:19pm » |
|
on Oct 10th, 2017, 8:19pm, Cor wrote:It's strange though, when you put the print loop before the sort statement, it shows the correct data at column 58 for 25 rows. |
|
Why is that strange? Since the bug is in the SORT statement, and at that point it hasn't yet been executed, you would surely expect the array to print correctly?
Quote:A slight error in LB?? Or in the definition of the sort statement in the help file?? |
|
We know it's not an error in the help file because experimentation (and LBB) confirm that SORT works the way it is documented to work. So it's definitely a bug (not a "slight" one in my opinion) and indeed, as Anatoly pointed out, it's already listed at the LB Bug Tracker Wiki here.
Richard.
|
|
Logged
|
|
|
|
|