Return number of elements or dimensions of an objectΒΆ

dim()

Return the number of elements in a subscripted field, or the number of dimensions of an object


SYNTAX

dim(object_id [, index])

This function can be used in two distinct ways.

1

If index is not present or is zero, then dim() returns the number of dimensions of the object object_id. This is always within the range 0 to 4.

2

If index is present, then dim() returns the number of elements in the dimension of object_id that is specified by index. The maximum number of dimensions permitted for a Sculptor field is 4, so values for index higher than 4 make no sense. If the field is not subscripted in the dimension specified, the function returns 0.


EXAMPLE

  1. Use of dim() to find the number of elements in an array:

    !temp Loop,,i2
    !temp Numbers,,i2[30]
    
         for (tmp.Loop = 1; tmp.Loop <= dim(Numbers, 1); tmp.Loop ++) {
              print tmp.Numbers[tmp.Loop]
         }
    
  2. Use of dim() to find the number of dimensions of an object:

    !temp Array[5,5,5]
    !temp NDims,,u1
    
         tmp.NDims = dim(tmp.Array)    /* tmp.NDims is set to 3 */
    

RELATED TOPICS

Field dimensions

redim()