Array length: Difference between revisions
Content deleted Content added
Line 729: | Line 729: | ||
I suppose the implicit DIM feature makes it a bit quicker to write short, simple programs. One or two dimension arrays may be resized with REDIM. Three dimension or more arrays can not be resized. All arrays may be cleared with REDIM. Keep in mind that A$(n) and A$(n,m) are the same array. You must refer to it with the correct arguments or get an error. |
I suppose the implicit DIM feature makes it a bit quicker to write short, simple programs. One or two dimension arrays may be resized with REDIM. Three dimension or more arrays can not be resized. All arrays may be cleared with REDIM. Keep in mind that A$(n) and A$(n,m) are the same array. You must refer to it with the correct arguments or get an error. |
||
NOTE -- This program |
NOTE -- This program runs only under LB Booster version 3.05 because of arrays with more than two dimensions, passed array names to functions and subroutines as a parameter, and structured error trapping syntax. Get the LBB compiler here: http://lbbooster.com/ |
||
Works with: LB Booster version 3.05 |
|||
<lang lb> |
<lang lb> |
||
Line 737: | Line 735: | ||
FruitList$(1)="orange" |
FruitList$(1)="orange" |
||
dimension=dimension(FruitList$()) 'first get the dimension of the array |
dimension=dimension(FruitList$()) 'first get the dimension of the array |
||
if dimension>3 then |
if dimension>3 then |
||
print "Sorry, program only written for array dimensions of 3 or less." |
|||
end |
|||
end if |
|||
call elements FruitList$(), dimension 'next get the size of each dimension |
call elements FruitList$(), dimension 'next get the size of each dimension |
||
end |
end |
||
Line 764: | Line 765: | ||
[TryNext] |
[TryNext] |
||
next dimension |
next dimension |
||
⚫ | |||
ArraySize(0)=dimension |
ArraySize(0)=dimension |
||
⚫ | |||
end function |
end function |
||
Line 771: | Line 772: | ||
select case dimension |
select case dimension |
||
case 1 |
case 1 |
||
try |
|||
do |
|||
x$=array$(a) |
|||
a+=1 |
|||
loop |
|||
catch: elements=a |
|||
end try |
|||
ArraySize(1)=elements-1 |
ArraySize(1)=elements-1 |
||
print "dimension 1 has "; elements; " elements (cells), "_ |
print "dimension 1 has "; elements; " elements (cells), "_ |
||
"numbered 0 to "; ArraySize(1) |
"numbered 0 to "; ArraySize(1) |
||
case 2 |
case 2 |
||
try |
|||
do |
|||
x$=array$(a,0) |
|||
a+=1 |
|||
loop |
|||
catch: elements=a |
|||
end try |
|||
ArraySize(1)=elements-1 |
ArraySize(1)=elements-1 |
||
print "dimension 1 has "; elements; " elements (cells), "_ |
print "dimension 1 has "; elements; " elements (cells), "_ |
||
"numbered 0 to "; ArraySize(1) |
"numbered 0 to "; ArraySize(1) |
||
elements=0 |
elements=0 |
||
try |
|||
do |
|||
x$=array$(0,b) |
|||
b+=1 |
|||
loop |
|||
catch: elements=b |
|||
ArraySize(2)=elements-1 |
end try ArraySize(2)=elements-1 |
||
print "dimension 2 has "; elements; " elements (cells), "_ |
print "dimension 2 has "; elements; " elements (cells), "_ |
||
"numbered 0 to "; ArraySize(2) |
"numbered 0 to "; ArraySize(2) |
||
case 3 |
case 3 |
||
try |
|||
do |
|||
x$=array$(a,0,0) |
|||
a+=1 |
|||
loop |
|||
catch: elements=a |
|||
end try |
|||
ArraySize(1)=elements-1 |
ArraySize(1)=elements-1 |
||
print "dimension 1 has "; elements; " elements (cells), "_ |
print "dimension 1 has "; elements; " elements (cells), "_ |
||
"numbered 0 to "; ArraySize(1) |
"numbered 0 to "; ArraySize(1) |
||
elements=0 |
elements=0 |
||
try |
|||
do |
|||
x$=array$(0,b,0) |
|||
b+=1 |
|||
loop |
|||
catch: elements=b |
|||
end try |
|||
ArraySize(2)=elements-1 |
ArraySize(2)=elements-1 |
||
print "dimension 2 has "; elements; " elements (cells), "_ |
print "dimension 2 has "; elements; " elements (cells), "_ |
||
"numbered 0 to "; ArraySize(2) |
"numbered 0 to "; ArraySize(2) |
||
elements=0 |
elements=0 |
||
try |
|||
do |
|||
x$=array$(0,0,c) |
|||
c+=1 |
|||
loop |
|||
catch: elements=c |
|||
end try |
|||
ArraySize(3)=elements-1 |
ArraySize(3)=elements-1 |
||
print "dimension 3 has "; elements; " elements (cells), "_ |
print "dimension 3 has "; elements; " elements (cells), "_ |