Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional number formatting in report 3

Status
Not open for further replies.

SitesMasstec

Technical User
Sep 26, 2010
470
1
18
BR
Hello colleagues!

In a program I have this code, in order for the user to define how many decimals he/she wants in a number, which saves "Quantity":
(Some users want quantity with no decimal places, other users, which work with kilograms want 3 decimal places in number for quantities).
Code:
IF QtCasasDec=0
	PICNUMERO="'999999'"         && No decimal 
ENDIF
IF QtCasasDec=1
	PICNUMERO="'999999.9'"       && One decimal place
ENDIF
IF QtCasasDec=2
	PICNUMERO="'999999.99'"      && Two decimal places
ENDIF
IF QtCasasDec=3
	PICNUMERO="'999999.999'"     && Three decimal places
ENDIF

I have a report with a field which shows "Quantity". In the 'Field Properties', Format, 'Format expression' I put
Code:
"&PICNUMERO"
but it doesn't work.

The other solution is to create 4 fields in the report, in the same position, with conditional printing depending on the value of the variable QtCasasDec. Is there other simpler solution?


Thank you,
SitesMasstec
 
Formatting the number as you want in the report field expression itself:
Code:
Transform(field,picnumero)

But don't have the single quotes within the strings.

Chriss
 
Cris, I noticed this inconvenience (quotation marks around the numbers):

RelatTransform_qiqclr.jpg


Report design:

ReportTransform_ir0cwa.jpg


Thank you,
SitesMasstec
 
SitesMasstec,
That is why Chris said "But don't have the single quotes within the strings".

So instead of establishing your value as PICNUMERO="'999999'" instead, make this PICNUMERO = "999999" or PICNUMERO = "999999.9"

Hence, take the "'" out.

The reason you don't need this is your field is already character type when you set it's value in "". So PICNUMERO = "999999" establishes this in VFP automatically as a TYPE() = Character (C). And if you display that, it will show as 999999, which might look like a numeric value, but it is in fact treated as character values. Whereas if you set PICNUMERO = 999999 now VFP will automatically treat this as TYPE() = Numeric (N). It's one of the things VFP does, you don't have to declare the type of value the way you would in other languages, VFP automatically uses the variable as the TYPE that it is when set. The thing to be aware of (and where other language purists get narky with VFP), is VFP dynamically changes the type based on what value is established.

So if this code where used:

PICNUMERO = "999"
PICNUMER = 999

VFP will not complain, and the value of picnumero will be 999 and numeric.
If we change this around

PICNUMER = 999
PICNUMERO = "999"

VFP will not complane either, and the value of picnumber will appear a 999 when displayed with ? or MESSAGEBOX(picnumero) but the data TYPE will be Character.

So what Chris is saying, take out the single quotes from your code around those values, and your problem will go away.


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
In general, when you need to place "quotes within quotes" like this, it can be difficult to distinguish between single quotes and double quotes. So in this string: "'999999'", you have to look closely to see the single quotes inside the double quotes. And conversely here: '"999999"' (both are equally valid, of course).

The solution is to use square brackets in place of one of the pairs of quotes: ['999999']. Syntactically it is exactly the same, but that much easier to read.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike, while this tip is generally good advice, it's not constructive in this case, because the second parameter of Transform must be the picture (format string) without the single quotes inside it. So there's no need to instruct how to put single quotes into a string in a way that's more distinctive.

If you look back into SitesMasstec first post you see he put a picture fomrmat string into single quotes and then quoted that in double quotes because he though macro substitution of that sting within the report control format would work. It doesn't, not only because of the quoting.

Chriss
 
SitesMasstec:

You see single quotes in the rpoert output, so what is causeing them? Have you thought about that?

Single quotes have no meaning in a picture formatting string, 9s have a menaing to show a digit in their place, the dot (.) has the meaning of the decimal point of a number, but does a quote have a meaning explainied in the help of the transform function? No, it does not, so it will be just diaplayed as is. As you don't want them, just remove them. It's straight forward.

Chriss
 
Solved, thank you all.

1) I took out the single quotes and the report is as expected now (PICNUMERO="'999999'" changed to PICNUMERO="999999")

2) A new problem appeared in a screen of the application, but I took out the & in PICTURE &PICNUMERO, and this new problem was gone:
Code:
@17,17 SAY YEQTDE PICTURE PICNUMERO COLOR RGB(&AzulClaro, &AzulMedio)

Code:
IF QtCasasDec=0
	PICNUMERO="999999"
ENDIF
IF QtCasasDec=1
	PICNUMERO="999999.9"
ENDIF
IF QtCasasDec=2
	PICNUMERO="999999.99"
ENDIF
IF QtCasasDec=3
	PICNUMERO="999999.999"
ENDIF
@17, 1 SAY "Quantidade .... "
@17,17 SAY YEQTDE PICTURE PICNUMERO COLOR RGB(&AzulClaro, &AzulMedio)
@18, 1 SAY "Estoque minimo  "
@18,17 SAY YEEMIN PICTURE PICNUMERO COLOR RGB(&AzulClaro, &AzulMedio)

Thank you,
SitesMasstec
 
SitesMasstec,

that explains why you had the quotes within the string. You overuse macro substitution. Indeed the @SAY command is cleaner and more direct that way.

Full syntax of the command is here, by the way:
To give you a hint on what to do to not need macro substitution in the RGB clause of the COLOR option of @SAY:
Code:
#Define BLACK 0,0,0
#Define YELLOW 255,255,128
@0,0 SAY 'SitesMasstec' Color Rgb(BLACK,YELLOW)

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top