There is a rather nice feature of UniBasic FIELD function which can return more than one sub string (field). But it is not in the SB+ expression elements nor paragraph statements.

So , I decided to create one!

Paragraph XFIELD:


LOCAL PARAM.STR, DELIM, OCCUR, NUM.SUBSTR
EQUATE EMPTY.STR TO ""
EQUATE COMMA TO ","
*
* Get parameters in order of FIELD function - see UniBasic manual for FIELD
PARAM.STR = FIELD(@PARAM, COMMA, 1)
DELIM = FIELD(@PARAM, COMMA, 2)
OCCUR = FIELD(@PARAM, COMMA, 3)
NUM.SUBSTR = FIELD(@PARAM, COMMA, 4)
*
* Call routine to do FIELD extended - return to @VALUE
CALL XFIELD(@VALUE, PARAM.STR, DELIM, OCCUR, NUM.SUBSTR)
*

Function XFIELD:


0001 FUNCTION XFIELD(PARAM.STR, DELIM, OCCUR, NUM.SUBSTR)
0002 ******************************************************************
0003 * eXtended FIELD function - see UniBasic FIELD documentation
0004 *
0005 * INPUT - PARAM.STR - String to extract from
0006 *       - DELIM     - Delimiter
0007 *       - OCCUR     - Occurrance of substringto start extraction
0008 *       - NUM.STR   - Number of substrings to return
0009 *
0010 * OUTPUT - RETURN - Result from FIELD function
0011 *
0012 ******************************************************************
0013 *
0014 *
0015       RESULT = FIELD(PARAM.STR, DELIM, OCCUR, NUM.SUBSTR)
0016
0017       RETURN(RESULT)
0018

Limitations are that the transferred parameters can not be multivalued, whereas the UniBasic function can handle this. Oh well..

As an afterthought, if multivalued operations are required, you could use the MATH expression element. See DMSKELCODE STRING.MATH for ideas.

You will see that if you call a UniBasic function the result is returned as the first parameter; therefore an extra parameter must be added in the call statement. Neat.

I suppose that you can do any missing UniBasic function this way. Remember to Generate Source Code for paragraph XFIELD to keep the speed up.

save.run.done.