Rocket U2 | UniVerse & UniData

 View Only

 Is there any way to determine the size of a dimensioned array at runtime?

Joe Goldthwaite's profile image
Joe Goldthwaite posted 02-29-2024 19:36

I want to iterate through and array passed to a subroutine but I need to know how many elements are in the array.

Henry Unger's profile image
PARTNER Henry Unger

Use the INMAT() function, which, in UniVerse, returns a dynamic array.

subroutine foo(mat bar)

dim bar(1)

n  = int(inmat(bar)<1, 1>)

Henry

Jonathan Smith's profile image
ROCKETEER Jonathan Smith

Joe,

You could use DCOUNT to do this, DCOUNT(ARRAY,@AM) for example will count the number of attributes in the array. DCOUNT(ARRAY<2>,@VM) would count the number of mulitvalues in attribute 2.

If you just want to parse the array you could use REMOVE to do this as you do not need to know the number of elements in an array to use REMOVE to process the whole array.

Thanks,

Joe Goldthwaite's profile image
Joe Goldthwaite

Thanks Henry, that's what I needed. I had seen the INMAT function but the documentation made it seem like it was for determining how many elements a MATREAD  had processed or to determine if the DIM statement succeeded.  Further down it mentions that use can use it to get the size of a dimensioned array. I just didn't read down that far.

Jonathan,

I appreciate the response. I was trying to figure out a function that would work with dimensioned arrays. They're a different animal from dynamic arrays which are basically a delimited string.

Thanks guys!