× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Bob,

>Would this work?

Not quite.

First, why set the lengths at 4096 varying?  Character fields can exceed that
and then you'll have a non-obvious program bug.  I haven't tested it, but if the
caller had a varying legth field with 16K of data and called your Right()
procedure as coded, wouldn't it see just the first 4K of the original field?
Then the procedure would run without an "error" but return the wrong characters
from the first argument.  Not pretty.

Second, the IF/ENDIF block looks like it correctly handles those cases where
nCharCnt is positive and less than or equal to the trimmed length of the input
string (when under 4K).  But what about the rest of the time?

What does "return  *" mean in RPG IV?   I can't find it documented.  Factor 2 is
supposed to be an expression, and * would suggest a unary multiplication but
that is obviously not what you mean here.  Is this supposed to represent a
pointer to something?  Or that a varying length field with a current length of
zero should be returned?  Is it even valid syntax?

If "return  *" means return a zero-length varying string, then it will catch
those cases where nCharCnt is passed as zero.

Third, what happens in this case?

  C  Eval  somefield = 'abcde'
  C  Eval myRightValue = Right( somefield : 10 )

Since 10 exceeds the trimmed length of somefield, you'd return a zero-length
string, assuming that is what "return  *" means.  But in my book, the above
should return 'abcde', not a zero-length string.

Or at least that is how I've always used Right() in VBA, and how *I'd* expect it
to work if I saw a Right() function.

These are the first three things I spot wrong with the code -- I didn't test it.

Doug


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.