xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HaaGetRealPos()

Retrieves the sort order of a key in an associative array.

Syntax

HaaGetRealPos( <hArray>, <nPos> ) --> nSortOrder

Arguments

<hArray>
A variable referencing the associative array to search a key in.
<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 a numeric value representing the sort order of <xKey> in the associative array <hArray>, or 0 if the key does not exist.

Description

Keys are internally held in an associative array by their sorting order. Function HaaGetRealPos() is used to determine this sorting order of a key in an associative array. The ordinal position of a key is returned by HaaGetPos().

Info

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

Example

// The example outlines the difference of the ordinal position
// of a key and its sorting order in an associative array

   PROCEDURE Main
      LOCAL hArray := Hash(), i, nReal

      HSetAACompatibility( hArray, .T. )

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

      FOR i:=1 TO Len( hArray )
         ? i, HGetKeyAt( hArray, i )
      NEXT
      ** Output:
      // 1 Five
      // 2 Four
      // 3 One
      // 4 Three
      // 5 Two

      FOR i:=1 TO Len( hArray )
         nReal := HaaGetRealPos( hArray, i )
         ? nReal, HGetKeyAt( hArray, nReal )
      NEXT
      ** Output:
      // 3 One
      // 5 Two
      // 4 Three
      // 2 Four
      // 1 Five
   RETURN

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