(c) M Web Magazine

Chris Bonnici's "Correct" Routines

Shareware Version

List of topics:

1. Introduction

2. The Source

3. Installation

4. Running the Program

5. Shareware

6. Distribution and Disclaimer

7. Contacting the Author

8. Click here to download

 

Introduction

This library came into being as an extension of MWM005’s tutorial. What better way to explain a function than to write your own version utilizing only the functions you have discussed?

Rather than copy the existing return codes of some M functions we have "corrected" them. The word correct is a very wobbly term to use as its definition varies from one person to another. In the authors opinion, the results returned by the items in this library are more consistent with some other language and that is how "correct" came into being.

 

Command Alternative Differences
$F $$CBF^CBRTN1
(STRING,SUBSTR,BEGIN)
This function returns the actual position of the found substring in string or 0 if not found or null.
$L $$CBL^CBRTN1
(STRING,SUBSTR,BEGIN,END)
The returns the correct count of substrings in string. Also allows the user to count the number of substrings within a section of string.
$E $$CBE^CBRTN1
(STRING,BEGIN,END)
Automatically swaps BEGIN and END if they don’t follow.

Allows Programmer to specify a BEGIN larger than END and automatically adjust them.

 

The Source

CBRTN1Þ; Chris Bonnici's Intrinsic Function Enhanced v 1.0 - Chris Bonnici - August 1997
Þ;(c) 1997 Chris Bonnici - All rights reserved
Þ;You may freely to distribute this library of routines as long as:
Þ; 1. You provide the entire archive WITHOUT ANY MODIFICATIONS
Þ; 2. You do not charge for the program
Þ; 3. You are using this program at your own risk
Þ;
Þ; Chris Bonnici: email: chribonn@softhome.net
Þ; URL: http://geocities.datacellar.net/SiliconValley/7041/ (latest version of this library).
Þ;
Þ; There is no charge if you are using this library for personal purposes although an e-mail is appreciated.
Þ; If this library is used within a commercial environment a registration fee of $15 is mandatory after the 30 day trial period.
Þ; Any income earned from this program will be used to initIate some projects in M Web Magazine at http://geocities.datacellar.net/cbonnici
Þ;
Þ; Thanks for your support
Þ;
Þ;Chris Bonnici's $F - Returns 'Correct' position match (i.e. $F-1) plus returns 0 with null substring
CBF(STRING,SUBSTR,BEGIN)ÞN I,J,FOUND
ÞQ:'$D(SUBSTR)!(SUBSTR="") 0
ÞS:'$D(BEGIN) BEGIN=1
ÞS J=1,FOUND=0
ÞF I=BEGIN:1:$L(STRING) D  Q:FOUND
Þ.I $E(STRING,I)=$E(SUBSTR,J) S J=J+1 S:J>$L(SUBSTR) FOUND=1 Q
Þ.S J=1
Þ.Q
ÞQ:FOUND I ;Return 'Correct' Position
ÞQ 0 ;Not Found
Þ;*** EOR ***
Þ;Returns correct count of substrings in string. Allows user to count within a substr
CBL(STRING,SUBSTR,BEGIN,END)ÞN COUNT,TEMP
ÞS:'$D(SUBSTR) SUBSTR=""
ÞQ:SUBSTR="" 0
ÞS:'$D(BEGIN) BEGIN=1
ÞS:'$D(END) END=$L(STRING)
ÞI BEGIN>END S TEMP=BEGIN,BEGIN=END,END=TEMP
ÞS STRING=$E(STRING,BEGIN,END),(BEGIN,COUNT)=0
CBL10ÞS BEGIN=$$CBF(STRING,SUBSTR,BEGIN) Q:BEGIN=0 COUNT
ÞS COUNT=COUNT+1,BEGIN=BEGIN+1
ÞG CBL10
Þ;*** EOR ***
Þ;Allows Programmer to specify a BEGIN larger than END
CBE(STRING,BEGIN,END)ÞN TEMP
ÞS:'$D(BEGIN) BEGIN=1
ÞI $D(END) D  Q $E(STRING,BEGIN,END)
Þ.I BEGIN>END S TEMP=BEGIN,BEGIN=END,END=TEMP
Þ.Q
ÞQ $E(STRING,BEGIN)

 

Installation

Open the ZIP archive.

Run your version of MSM

Using %RR, load the file CBRTN1.RTN into your development UCI.

 

Running the program.

Check out MWM005’s M Tutorial section for information about the $ functions replaced.

From with your programs call $$xxx^CBRTN1, where xxx is the name of the function..

 

Shareware

CBRTN1 is a shareware program and there is no charge if you are using this library for personal purposes although an e-mail is appreciated. If this program is used within a commercial environment a registration fee of $15 is mandatory after the 30 day trial period.

Any income earned from this program will be used to initiate some projects in M Web Magazine at http://geocities.datacellar.net/cbonnici so if you can pitch in you’ll see your donation turned into something useful to the entire M community.

For corporate licensing please contact the author.

 

Distribution and Disclaimer

CBRTN1 may be distributed by any means, provided that the original files as supplied by the author remain intact. This program may be placed on any archive or BBS system.

If used in a commercial environment, the program must be registered if used beyond the evaluation period.

This program can not be bundled with any commercial package or distributed by itself (i.e. separate from the rest of the archive) without express written permission from the author.

The author of this program accepts no responsibility for damages resulting from the use of this product and makes no warranty or representation, either express or implied, including but not limited to, any implied warranty of merchantability or fitness for a particular purpose. This software is provided "AS IS", and you, its user, assume all risks when using it.

By installing this program you implicitly agree to the rules outlined above.

 

Contacting the Author

The latest version of this program can always be downloaded from Chris Bonnici's M Page http://geocities.datacellar.net/SiliconValley/7041). Choose from the index Download M.

Electronically, Chris Bonnici can be reached at chribonn@softhome.net.

Comments and suggestions are welcome.

"Any income earned from this program will be used to initiate some projects in M Web Magazine"

Fill in the Survey

E&OE

Tell a Friend!

1