Skip navigation


The LOCATE function is the most commonly use function for a multi-value system.
It searches for the location of a specific string expression into a dynamic array.
And it may be arrange in a sequence ascending or descending and sorted with either right or left justification.

SYNTAX
LOCATE(string, dynamic.array {, ac{, vc{,start}}}; position {; sequence} ) [THEN | ELSE statement.block]

Since it is design to identify the position of an string expression into a dynamic array, it can also be use for a numeric express.
But there is a minimal issue when using LOCATE with sequence option in an array with precession (decimal) element.

EXAMPLE
We have an dynamic array with 1 elements.
And our task is to insert other 4 elements and must be in ascending order.

Since it is design to identify the position of an string expression into a dynamic array, it can also be use for a numeric express.
But there is a minimal issue when using LOCATE with sequence option in an array with precession (decimal) element.EXAMPLE
We have an dynamic array with 5 elements.
And our task is to insert it into new array and must be in ascending order.


array=''
list.array = 4.5 :@VM: 21 :@VM: 8.1 :@VM: 32 :@VM: 70
FOR v = 1 TO 5
LOCATE(list.array<1,v>,array,1;position;'ar') THEN NULL
array = INSERT(array,1,position;list.array<1,v>)
NEXT v
FOR a = 1 TO 5
PRINT array<1,a> :"-":
NEXT a

OUTPUT
21-32-4.5-70-8.1

The output is not what we are expecting.
And notice that the decimal is ignore by the LOCATE function.

To satisfy our desire output, the trick is to eliminate the precession of the value. One method is to multiply the value to 100, assuming you only keep two (2) decimal places into your data.


array =''
list.array = 4.5 :@VM: 21 :@VM: 8.1 :@VM: 32 :@VM: 70
FOR v = 1 TO 5
LOCATE(list.array<1,v>*100,array,1;position;'ar') THEN NULL
array = INSERT(array,1,position;list.array<1,v>*100)
NEXT v
FOR a = 1 TO 5
PRINT array<1,a>/100 :"-":
NEXT a

OUTPUT
4.5-8.1-21-32-70

Now, that much better.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: