STAB_GetElemByInt

The STAB_GetElemByInt function returns a string stored with a specific integral value in a STAB object.

extern STAB_GetElemByInt
  float handle         // handle to STAB
  float searchval      // search value
  stringvar strdata$   // string variable to receive matching string
  floatvar index       // float variable to receive matching string's index

Parameters

handle
[in] Handle to a STAB object previously returned from STAB_Create.
value
[in] The associated value to find in the STAB object.
strdata$
[out] The string variable that will be set with the first string that has an associated float value of searchval.
index
[out] The float variable that will be set with the index of the matching string, or -1 if a match was not found.

Remarks

If handle is not a valid STAB handle, an error message will be printed to the console.

STAB_GetElemByInt compares the value of searchval rounded to the nearest integer with each string's associated float value, also rounded to the nearest integer. It returns the first matching index, if one exists.

To perform a search for an exact float match instead using the nearest integer, use STAB_GetElemByFloat.

Example

extern STAB_Create handle
extern STAB_Append handle "a" 0.3
extern STAB_Append handle "b" 1.5
extern STAB_Append handle "c" 2.1
extern STAB_GetElemByInt handle 2 str$ idx

At the end of this code fragment, str$ will have a value of "b" and idx will have a value of 1.