PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: michaelgreer on September 17, 2019, 10:45:11 AM

Title: Weird programming result
Post by: michaelgreer on September 17, 2019, 10:45:11 AM
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.
Title: Re: Weird programming result
Post by: James Zukowski on September 17, 2019, 10:56:58 AM
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.
Title: Re: Weird programming result
Post by: michaelgreer on September 17, 2019, 11:11:31 AM
Thanks James. I did fix the issue, but I didn't realize that everything after that "+" sign got interpreted as part of the mask.
Title: Re: Weird programming result
Post by: James Zukowski on September 17, 2019, 11:13:34 AM
Yep. It's just one BIG string/mask expression when using "+".
Title: Re: Weird programming result
Post by: Mike King on September 19, 2019, 04:34:32 PM
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.