dimOf Function

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Retrieves the number of index elements for which space has been allocated in an X++ array.

int dimOf(anytype object)

Parameters

Parameter

Description

object

The array of which to determine the dimension size.

Return Value

If the value of the object parameter is an array, the return value equals the number of elements in the array; otherwise, zero.

Remarks

The dimOf function applies to X++ arrays that are declared as certain X++ primitive types, such as int or boolean. An example is int iAmounts[6];. dimOf does not apply to instances of the Array class of Microsoft Dynamics AX.

The dimOf function is intended for arrays of the following primitive types in X++:

  • boolean

  • date

  • int

  • int64

  • real

  • utcDateTime

Arrays of enumeration values and extended data types are also supported if they are ultimately based on any one of the preceding primitive data types (such as int).

The dimOf function does not accept arrays of all X++ primitive types. The array types that dimOf does not accept are as follows:

  • str

  • container

  • anytype

  • Arrays of class objects

  • An instance of the Array class

Code Sample

The following X++ code demonstrates the behavior of the dimOf function for a variety of array concepts.

    static void JobDimOfArrays(Args _args)
    {
        int iAmounts[20]
            ,iCounts[];
        ABCModel enumAbcModel[22]; // Enum
        ABCModelType exdtAbcModelType[24]; // Extended data type
        anytype anyThings[26];
        str sNames[28];
        Array myArrayObj; // Class
        ;
        info("Start of job.");
    
        info("--(Next, normal int array, dimOf() accepts it.)");
        info(int2Str(dimOf(iAmounts)));
    
        info("--(Next, normal enum array, dimOf() accepts it.)");
        info(int2Str(dimOf(enumAbcModel)));
    
        info("--(Next, normal extended data type array (based on enum), dimOf() accepts it.)");
        info(int2Str(dimOf(exdtAbcModelType)));
    
        info("--(Next, dynamic int array, dimension not yet set.)");
        info(int2Str(dimOf(iCounts)));
        info("--(Next, dynamic int array, after dimension established.)");
        iCounts[13] = 13;
        info(int2Str(dimOf(iCounts)));
    
        info(" == == == == == (Next, array types that dimOf() does not support.)");
    
        info("--(Next, normal anytype array, dimOf() always returns 0.)");
        info(int2Str(dimOf(anyThings)));
    
        info("--(Next, an instance of class X++ Array, dimOf() always returns 0.)");
        myArrayObj = new Array(Types::Integer);
        myArrayObj.value(1,501);
        info(int2Str(dimOf(myArrayObj)));
        info("--(Next, the lastIndex method provides size information about Array instances.)");
        info(int2Str(myArrayObj.lastIndex()));
    
        info("--(Next, normal str array, dimOf() does not accept it, job is halted.)");
        info(int2Str(dimOf(sNames)));
    
        info("End of job.");
    
    /************  Actual Infolog output
    Message (11:10:06 am)
    Start of job.
    --(Next, normal int array, dimOf() accepts it.)
    20
    --(Next, normal enum array, dimOf() accepts it.)
    22
    --(Next, normal extended data type array (based on enum), dimOf() accepts it.)
    24
    --(Next, dynamic int array, dimension not yet set.)
    0
    --(Next, dynamic int array, after dimension established.)
    16
     == == == == == (Next, array types that dimOf() does not support.)
    --(Next, normal anytype array, dimOf() always returns 0.)
    0
    --(Next, an instance of class X++ Array, dimOf() always returns 0.)
    0
    --(Next, the lastIndex method provides size information about Array instances.)
    1
    --(Next, normal str array, dimOf() does not accept it, job is halted.)
    Error executing code: Illegal operation on this type of array. (C)\Jobs\JobDimOfArrays - line 41
    ************/
    
    /***********  Pop-up error dialog box
    "Internal error number 25 in script."
    
    This error is caused by the code line...
        info(int2Str(dimOf(iCounts)));
    ...before iCounts was assigned at any index.
    ***********/
    }

See also

Functions

Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).