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:


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

Comments
SELECTSTR treats string values as OPTIONS. This
means that identical values in different strings are not allowed.

 

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.

Advertisements
Tagged with:
Posted in NAV
2 comments on “SELECTSTR limitations in NAV
  1. Could be the greatest blog post I have ever seen!

  2. I could not think you are more right..

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: