xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HaaGetKeyAt()

Retrieves the key from an associative array by its ordinal position.

Syntax

HaaGetKeyAt( <hArray>, <nPos> ) --> xKey

Arguments

<hArray>
A variable referencing the associative array to retrieve a key from.
<nPos>
A numeric value specifying the ordinal position of the key/value pair to query. It must be in the range between 1 and Len(<hArray>).

Return

The function returns the key at position <nPos> in the associative array <hArray>.

Description

This function retrieves the key from the associative array <hArray> at position <nPos>. If <nPos> is outside the valid range, a runtime error is raised. Use function HaaGetPos() to determine the ordinal position of a key.

The keys are inserted into the associative array by their sorting order and cannot be moved or changed.

Info

See also:Array(), HaaGetValueAt(), HaaSetValueAt(), Hash(), HSetAACompatibility()
Category: Associative arrays , Hash functions , xHarbour extensions
Source:vm\hash.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates that keys are collected in an
// associative array by their sorting order.

   PROCEDURE Main
      LOCAL hArray := Hash()

      HSetAACompatibility( hArray, .T. )

      hArray[ "One"  ] := 10
      hArray[ "Two"  ] := 20
      hArray[ "Three"] := 30
      hArray[ "Four" ] := 40
      hArray[ "Five" ] := 50

      ? HGetKeyAt( hArray, 1 )    // result: Five
      ? HGetKeyAt( hArray, 5 )    // result: Two

      ? hArray[1]                 // result: 10
      ? hArray[5]                 // result: 50
   RETURN

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