vrijdag 13 juni 2008

SELECTSTR limitations in NAV

There is a function in NAV that enables you to retrieve a string at a certain position in a comma seperated string.

There are a few limitations to this functions.
  1. You are foreced to use a comma ','
  2. You cannot use the same string twice in the same comma seperated string



From the NAV help file:
Comments
SELECTSTR treats string values as OPTIONS. This
means that identical values in different strings are not allowed.


A simple solution can be found on mibuso. Using this function removed both limitations as you can specifiy which seperation value to use.



fctGetFieldContent(pFieldNo : Integer;pText : Text[1024]) : Text[1024]
// ******************************************************************* //
// Code From Mibuso: //
// http://www.mibuso.com/forum/viewtopic.php?t=1429&highlight=strset //
// ******************************************************************* //

ReturnString := '';
FieldsFound := 1;
boo := -1;
REPEAT
CounterPos += 1;
IF pText[CounterPos] = '"' THEN
boo *= -1
ELSE BEGIN
IF (pText[CounterPos] = ',') AND (boo = -1) THEN
FieldsFound += 1
ELSE
IF FieldsFound = pFieldNo THEN
ReturnString := ReturnString + COPYSTR(pText,CounterPos,1);
END;
UNTIL (CounterPos = STRLEN(pText)) OR (FieldsFound > pFieldNo);

EXIT(ReturnString);



NOTE: You could also pass the seperation string to the function and replace the line IF (pText[CounterPos] = ',') AND (boo = -1) THEN with IF (pText[CounterPos] = pSerperator) AND (boo = -1) THEN

All credits go to PrebenRasmussen who posted this on Mibuso.

Geen opmerkingen: