xHarbour Reference Documentation > Function Reference |
Retrieves the key from an associative array by its ordinal position.
HaaGetKeyAt( <hArray>, <nPos> ) --> xKey
The function returns the key at position <nPos> in the associative array <hArray>.
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.
See also: | Array(), HaaGetValueAt(), HaaSetValueAt(), Hash(), HSetAACompatibility() |
Category: | Associative arrays , Hash functions , xHarbour extensions |
Source: | vm\hash.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com