David J Murray
~ Learn and Do - Excel and Share ~

XFIELD – eXtended FIELD process

Aug 25, 2006

Image by Chaos07 from Pixabay

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.

About the Author

<a href="https://davidjmurray.org/author/davidjmurray/" target="_self">djm</a>

djm

I have been in the computer/IT industry for over 35 years. After spending half a life-time in highly proprietary database environments, I have succumbed to the WordPress Eco-system and I'm well down the chasm. I am specializing in AWS hosting, Wordpress CMS, Elegant Themes, in particular Divi and Extra themes.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This