Skip to main content
Question

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

  • February 29, 2024
  • 3 replies
  • 1 view

Joe Goldthwaite

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

3 replies

Henry Unger
Forum|alt.badge.img+3
  • Inspiring
  • 35 replies
  • February 29, 2024

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

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
Forum|alt.badge.img
  • Rocketeer
  • 356 replies
  • March 1, 2024

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

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
  • Author
  • Participating Frequently
  • 124 replies
  • March 1, 2024

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

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!