Locate Statement (OpenInsight)
At 18 JUL 2001 03:17:32PM Richard Richter wrote:
I am having a problem with the Locate Statement. Maybe I'm not using the correct statement. Here's what I'm trying to do:
I have a string of numbers seperated by @VM:
1:@VM:2:@VM:3:@VM:4I am trying to find the position to insert a number, for example 2.5 would be positioned between postion 2 and 3 and therefore I need to get that position, either 2 or 3.
If I use locate, I don't get any result, not even one greater than the number of positions in the string (5 in this case).
Is there any command I can use? I tried Locate and Locate By to no avail.
Thanks for you help,
Richard Richter
At 18 JUL 2001 03:32PM Don Miller - C3 Inc. wrote:
You can use ..
LOCATE BY like:
TSTVAL=1:@VM:2:@VM:3
LOCATE 2.5 IN TSTVAL BY "AR" SETTING WHERE_FOUND ELSE
WHERE_FOUND WILL CONTAIN WHERE TO INSERT IF IT FAILSTSTVAL=INSERT(TSTVAL,1,WHERE_FOUND,0,"2.5")END ELSE
FOUND IT SO JUST SKIP IT SINCE IT'S ALREADY THEREEND
HTH
Don Miller
C3 Inc.
At 19 JUL 2001 09:06AM Mike Ruane wrote:
Richard-
If your initial list is sorted, use LOCATE…BY.
From Help:
Use this version of Locate when you are dealing with sorted data. This statement returns the location where a specified string should be inserted, according to the specified sorting consideration.
The By clause in the BASIC+ Locate…By statement locates the sorted position (index) of a value.
Parameter Description
substring Specifies the value whose position is to be located in string.
string Designates the string that is to be searched.
seq Locate…By uses seq to determine placement of substring. The By clause must follow the in clause in this general format. The seq parameter may have any of the following values:
Value Justification
AL Ascending, Left-justified.
AR Ascending, Right-justified (numeric).
DL Descending, Left-justified.
DR Descending, Right-justified (numeric).
delim Specifies the character that is to be used in the search for the substring. It may be any ASCII character. If dynamic arrays
are being searched, delim should be a field mark (@FM),
value mark (@VM), or a subvalue mark (@SVM). If a Using clause is not specified, a value mark is assumed.Do not include a delim character in a string expression.
Hope it helps-
Mike