ARRAY LOOKUP()

From Lianjapedia
Jump to: navigation, search

PURPOSE

Look up value in an array

SYNONYM

api_array_lookup()

SYNOPSIS

#include "lianja_api.h"
 
struct API_MEMVAR	ARRAY_LOOKUP(arrayname, element)
 
<input parameters>
char	*arrayname;	/* Address of a buffer containing the name of an array	*/
int	element		/* Number of element					*/
 
<output parameters>
none

DESCRIPTION

The ARRAY_DEFINE() function returns the data type, value, display width and number of decimal places of the specified element number in the array.

NOTE: array elements start at 1 and not 0 as in 'C'.

A NULL value is returned if the array has not been previously been defined or the specified array element is out of range, otherwise the results are stored in the following API_MEMVAR data structure.

union	API_UNION {
    char			*info_character;		/* char memory variable			*/
    char			info_logical;		/* logical memory variable		*/
    double		info_number;		/* numeric memory variable		*/
    unsigned long	info_date;			/* date memory variable			*/
    DATETIME		info_datetime;	 	/* datetime memory variable		*/
    CURRENCY	info_currency;		/* currency memory variable		*/
};
 
struct	API_MEMVAR {
    char			type;				/* data type of memory variable	*/
    union		API_UNION value;	/* value of the memory variable	*/
    int			width;			/* display width				*/
    int			decimal;			/* display # of decimal places		*/
};

The API_MEMVAR type specifies both the data type and which API_UNION value will be used to return the value of the array element.

The API_MEMVAR width returns the length of the array element. A decimal place may be returned for a number, but will be 0 for other data types.

An array element can be defined as any one of the following.


TYPE OUTPUT WIDTH DESCRIPTION
C info_character 1 - 8192 address of a buffer containing a character string
D info_date 8 unsigned long representing a Date
L info_logical 1 character of either 'T' for true or 'F' for false
N info_number 1 - 16 a value stored in a double
T info_datetime sizeof(DATETIME) RCT_DATETIME_DEF structure
Y info_currency sizeof(CURRENCY) RCT_CURRENCY_DEF structure

EXAMPLE

The following example looks up the array element and returns the result.


#include <stdio.h>
#include "lianja_api.h"
 
lianjaapi_array_lookup()
{
    struct API_MEMVAR	result
 
    if (_parinfo(1) != API_CTYPE || _parinfo(2) !=API_NTYPE) {
       _retc("")
    }
 
    result = ARRAY_LOOKUP(_parc(1), _parni(2));
 
    switch (result->type)
    {
       case 'C':
       ''retc( result->value.info''character );
       case 'D':
       _retc(DATE_DTOS(result->value.info_date));
       case 'N':
       CHAR_STR(buffer,
       result->value.info_number,
       result->width,
       result->decimal);
       _retc(buffer);
       case 'L':
       _retc((result->value.info_logical=='T') ? "True" : "False");
       case 'T':
       _retc(DATE_TTOS(result->value.info_datetime));
       case 'Y':
       _retc(CURR_YTOS(result->value.info_currency));
    }
 
}

SEE ALSO

_parinfa(), ALENGTH(), ISARRAY(), ARRAY_ALEN(), ARRAY_DEFINE(), ARRAY_UPDATE()