Weird programming result

Started by Michael Greer, September 17, 2019, 10:45:11 AM

Previous topic - Next topic

Michael Greer

On PxPlus 12.51 I see this:
2260 print (10)@(30),fnif(sorsop.type$="D",num(sorsop.orig_amt$),-num(sorsop.amount$)):y3$+" "+tbl(pos(sorsop.type$="DEORAT")-1,"",sorsop.reason$+" "+forfeit_reason$,"",sorsop.memo$,"",sorsop.note$); l=l+1; goto NEXT_DEP_TRANS

The contents of sorsop.memo$+sorsop.notes$ is ABCABCABCABCABCABC BLUE BUBBLES.  All of the B's are dropped, whether printing to a device (notepad) or to the console.  Note what should probably throw an error is that the first output is a masked numeric field passed through y3$ which is concatenated to a string value.  Simply changing that "+" to a comma rectifies the issue.  Attached doc shows this.

James Zukowski

Evidently, the implicit numeric formatting into the string uses "y3$+...,sorsop.note$)" as the mask applied to the numeric value. If the code is change to use the STR() function, it should work fine:
str(fnif(sorsop.type$="D",num(sorsop.orig_amt$),-num(sorsop.amount$)):y3$)+" "+...
A "B" in a mask is used to indicate a blank space position, which is why the "B"s disappeared.
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Michael Greer

Thanks James. I did fix the issue, but I didn't realize that everything after that "+" sign got interpreted as part of the mask.

James Zukowski

Yep. It's just one BIG string/mask expression when using "+".
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Mike King

Just to clarify; in a PRINT directive a numeric variable followed by a ":" indicates that a string expression follows which till define the format to use when outputting the number.

In your case the '+' was considered part of the string expression and thus the subsequent string text was included as the format.   To avoid this use a comma to separate the values.
Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com