SELECTSTR and Optionstrings

When you try to acces a value in an Optionstring with the SELECTSTR function you will get an error if the Optionstring is “,” at this position. As an example compare the field “Type” in the Purchase and the Sales Line and try this: RecRef.OPEN(39); FieldRef := RecRef.FIELD(5); // Type MESSAGE(SELECTSTR(4,FieldRef.OPTIONSTRING)); You will get “The value for SELECTSTR parameter no. 2 is not valid.” To avoid this situation I use my own function which might be not so fast as SELECTSTR. But it still works [;)] SelectStrWithBlanks(vin_Position : Integer;vtx_String : Text[255]) : Text[255] lin_CommaCounter := 1; ltx_Dummy := ''; FOR x:=1 TO STRLEN(vtx_String) DO BEGIN IF vtx_String[x] = ',' THEN lin_CommaCounter += 1 ELSE IF lin_CommaCounter = vin_Position THEN ltx_Dummy += COPYSTR(vtx_String,x,1); END; IF lin_CommaCounter < vin_Position THEN ERROR(ERR_NO_VALID_POSITION, vin_Position, lin_CommaCounter, vtx_String); EXIT(ltx_Dummy);

In standard Navision options start with 0 as the first option; in FieldRef options start with 1. You try to refer to option 4 which is blank - and that causes an error (do not know why). If you try 5 as selectstr-parameter you should get “Fixed Asset”.

the problem is when you run through such an optionstring to find a values position. you cannot handle such a loop with the selectstr cause it throws the error when coming to the “,” part.