× 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.



Sounds like you're saying it will work unless someone has a huge text
field, in which case you can change the code, the source is there. I
don't see that as an issue.

VARYING allows you pass in a value of any length without worrying about
the length of the value passed in--its integrated into VARYING, so long
as it does not exceed the maximum length declared for the variable.

When the number of bytes (parm 2) exceeds the length of the input value,
you simply need to change one line of code and it will work the way "you
expect it to". Just change the RETURN '' line to RETURN InString. Not
rocket science. Also, remember, I sort of made up the routine as I wrote
it in the email message.

So I don't agree that you found things wrong with the code. I think you
found things that didn't fit your thinking of how Right() should work
(remember this is RPG IV, not Visual Basic) but as I said, you have the
source, so change it to make it work the way _you_ think it should work.

Thanks for the feedback.

Bob


> -----Original Message-----
> From: rpg400-l-admin@midrange.com
> [mailto:rpg400-l-admin@midrange.com] On Behalf Of Douglas Handy
> Sent: Tuesday, June 11, 2002 3:53 PM
> To: rpg400-l@midrange.com
> Subject: Re: right$
>
>
> 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
> _______________________________________________
> This is the RPG programming on the AS400 / iSeries (RPG400-L)
> mailing list To post a message email: RPG400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
> or email: RPG400-L-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
>
>



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.