xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

[ ] (array)

Array element operator (unary): retrieves array elements.

Syntax

<aArray>[<nSubScript,...>]
<aArray>[<nSubScript1>][nSubScript2][<...>]

Arguments

<aArray>
<aArray> is an expression which returns a reference to an array. This can be a memory variable, an instance variable or a function call that returns an array.
<nSubScript>
<nSubScript> is a numeric expression which indicates the ordinal position of the array element to retrieve. One subscript must be passed for each dimension of the array.

Description

The array element operator retrieves a value stored in an array element. The ordinal position of the desired element must be specified as a numeric value. Elements of multi-dimensional arrays are specified using one subscript value per array dimension.

Note:  if <nSubScript> is a negative value, the operator retrieves the element Abs(<nSubScript>) from the end of the array.

Info

See also:[ ] (string), { }, Array()
Category: Operators , Special operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows some variations of the use of the subscript operator.

   PROCEDURE Main
      LOCAL aArray := { "One", "Two", "Three" }
                                       // one dimensional array
      ? aArray[1]                      // result: One
      ? aArray[2]                      // result: Two
      ? aArray[3]                      // result: Three

      ? aArray[-1]                     // result: Three
      ? aArray[-3]                     // result: One

      USE Customer                     // two dimensional array
                                       // combined with function call
      ? DbStruct()[1,1]                // result: FIRSTNAME
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe