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 will only run under Liberty Basic Booster (LB Booster) because of arrays with more than two dimensions and structured error trapping syntax. Get the LBB compiler here: http://lbbooster.com/
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 end 'program only written for array dimensions of 3 or less
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
if dimension<4 then print "array dimension = "; dimension
ArraySize(0)=dimension
ArraySize(0)=dimension
print "array dimension = "; dimension
end function
end function


Line 771: Line 772:
select case dimension
select case dimension
case 1
case 1
do
try
try: x$=array$(a)
do
catch: elements=a: exit do
x$=array$(a)
end try
a+=1
a+=1
loop
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
do
try
try: x$=array$(a,0)
do
catch: elements=a: exit do
x$=array$(a,0)
end try
a+=1
a+=1
loop
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
do
try
try: x$=array$(0,b)
do
catch: elements=b: exit do
x$=array$(0,b)
end try
b+=1
b+=1
loop
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
do
try
try: x$=array$(a,0,0)
do
catch: elements=a: exit do
x$=array$(a,0,0)
end try
a+=1
a+=1
loop
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
do
try
try: x$=array$(0,b,0)
do
catch: elements=b: exit do
x$=array$(0,b,0)
end try
b+=1
b+=1
loop
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
do
try
try: x$=array$(0,0,c)
do
catch: elements=c: exit do
x$=array$(0,0,c)
end try
c+=1
c+=1
loop
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), "_