×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Conditional number formatting in report
3

Conditional number formatting in report

Conditional number formatting in report

(OP)
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

RE: Conditional number formatting in report

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

RE: Conditional number formatting in report

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



Report design:

Thank you,
SitesMasstec

RE: Conditional number formatting in report

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

RE: Conditional number formatting in report

2
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

RE: Conditional number formatting in report

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

RE: Conditional number formatting in report

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

RE: Conditional number formatting in report

(OP)
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

RE: Conditional number formatting in report

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: https://www.vfphelp.com/vfp9/html/087e146d-3b91-4b...

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close