fox
Junior Member
Posts: 66
|
Post by fox on Jun 12, 2018 11:27:49 GMT -5
Hi all. Please, I would like to know what is the simple way to know the dimensions of a array (single dimensioned) of which I don't Know the number of items. Thanks to all and bye fox
|
|
|
Post by tsh73 on Jun 12, 2018 14:52:55 GMT -5
There are NO simple way.
But you don't likely *get* array about which you don't know: arrays are global in LB, and could not be passed to sub/function.
So array a() in your sub will always be a() elsewhere. So you might as well store it's dimension in a variable.
just for kicks, one could try to access array items until it breaks. Last working would be array size.
n = int(rnd(0)*100) print n dim a(n)
print "size of A is ";sizeA() end
function sizeA() on error goto [err] for i = 1 to 100 dummy=a(i) next [err] 'then it die sizeA = i-1 end function
It could be made fast by using powers of two and binary search.
|
|
|
Post by tsh73 on Jun 12, 2018 15:00:41 GMT -5
Oh, I forgot EVAL so with EVAL you can pass array into subs. Kind of (only for reading)
n = int(rnd(0)*100) print n dim a(n)
print "size of a() is ";sizeA("a") dim b(7) print "size of b() is ";sizeA("b") dim c$(13) print "size of c$() is ";sizeA("c$")
end
function sizeA(arrName$) on error goto [err] for i = 1 to 100 dummy=eval(arrName$;"(";i;")") next [err] 'then it die sizeA = i-1 end function
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Jun 13, 2018 1:54:02 GMT -5
Thanks a lot, tsh73. Your help will be precious for me. Anyway I understood that the "simple way" is (as you suggested) to store the dimensions of the array in a variable. Thanks a lot again and bye fox
|
|