Compartir a través de


ASUBSCRIPT( ) Function

Returns the row or column subscript of an element from the element's number.

ASUBSCRIPT(ArrayName, nElementNumber, nSubscript)

Parameters

  • ArrayName
    Specifies the name of the array.

  • nElementNumber
    Specifies the element number.

  • nSubscript
    Determines if the row or column subscript is returned.

    If the array is one-dimensional, include the element number in nElementNumber and 1 in nSubscript. ASUBSCRIPT( ) identically returns nElementNumber.

    If the array is two-dimensional, include both the element number nElementNumber and a value of 1 or 2 in nSubscript. Specifying 1 in nSubscript returns the row subscript of the element, and specifying 2 returns the column subscript.

    For more information on how to reference elements in an array, see DIMENSION.

Return Value

Numeric

Remarks

You can refer to elements in two-dimensional variable arrays in one of two ways. The first method uses two subscripts to specify the row and column position of the element in the array. The second method uses an element number. Use ASUBSCRIPT( ) to obtain an element's row or column subscript from the element's number.

In the following example, an array with two rows and three columns is created. DISPLAY MEMORY shows the contents of the elements of the array listed in element number order.

DIMENSION gaMyArray(2,3)
DISPLAY MEMORY LIKE gaMyArray
GAMYARRAY  Pub  A
  ( 1, 1)   L  .F. (element number 1)
  ( 1, 2)   L  .F. (element number 2)
  ( 1, 3)   L  .F. (element number 3)
  ( 2, 1)   L  .F. (element number 4)
  ( 2, 2)   L  .F. (element number 5)
  ( 2, 3)   L  .F. (element number 6)

Each of these commands stores the character string INVOICE to the same array element:

STORE 'INVOICE' TO gaMyArray(2, 1)
STORE 'INVOICE' TO gaMyArray(4)

In one-dimensional arrays, an element's number is identical to its single row subscript. It isn't necessary to use ASUBSCRIPT( ) with one-dimensional arrays.

See Also

Reference

ADEL( ) Function

ADIR( ) Function

AELEMENT( ) Function

AFIELDS( ) Function

AINS( ) Function

ALEN( ) Function

ASCAN( ) Function

ASORT( ) Function

DIMENSION Command

DISPLAY MEMORY Command

Other Resources

Functions

Language Reference (Visual FoxPro)