Print Page | Close Window

How to align a field in Crystal through code

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5365
Printed Date: 05 May 2024 at 9:21am


Topic: How to align a field in Crystal through code
Posted By: ehy01
Subject: How to align a field in Crystal through code
Date Posted: 29 Jan 2009 at 12:40pm
I would like to align the data in a field depending on whether the field is numeric or not - but I cannot get the code to do it -
My pseudocode is (for Crystal)

if (ConditionA) then
   RightAlign
else
  leftAlign

How do I do it - I need the code
 
PLEASE!!!!Cry



Replies:
Posted By: DBlank
Date Posted: 29 Jan 2009 at 1:41pm
Right click on the field and select properties and select the Common Tab.
Next to the Horizontal Alignment click on the formula button. Your syntax options are in there but it would be something like:
If {table.field}=condition then crRightAligned else crLeftAligned


Posted By: ehy01
Date Posted: 29 Jan 2009 at 1:46pm

Thx for answer, but what i want is:

If {table.field}=condition then
   {table.field_2} = crRightAligned
else
    {table.field_2} = crLeftAligned
 
get it?
 
Somethig like that, the condition in one field align another field.
 
Ps:Sorry, my English is terrible... ^^


Posted By: DBlank
Date Posted: 29 Jan 2009 at 1:51pm
The process and formula are the same as i stated above but put the formula in your "field2" properties instead of "field1".
You can conditionally change one field's appearance based on any related field.
So, right click on field 2 (the one you want to change the text alignment) and insert the formula using field1 as your condition:
If {table.field}=condition then crRightAligned else crLeftAligned


Posted By: ehy01
Date Posted: 29 Jan 2009 at 2:07pm
This is my formula:
If {F_RelConciliacaoAuto.tp_Dados} = "V" then
   crRightAligned
Else
   crLeftAligned
 
Work's great in normal field, but...
There's another problem, i have a Cross tab and i need align the Title of columns based on the first cell of the same column. In this case the formula did not work. What can i do?
 


Posted By: DBlank
Date Posted: 29 Jan 2009 at 2:28pm
Hmmm. I have not had to use cross tabs very often but that is not an option to change text alignment there so you are out of luck.
Can you alter the report requirements to conditionally change some other characteristic like font color otr type? If so you can right click on the field and look at each of the different options. Wherever the conditiona formla is and is not greyed out you should be able to add a condition to change the field there.


Posted By: ehy01
Date Posted: 29 Jan 2009 at 4:25pm
Yeah, the place to input the conditional formula on the title of column is there, the problem is the formula isnt work.


Posted By: DBlank
Date Posted: 29 Jan 2009 at 8:16pm
Sorry but I am not sure what the condition is that needs to be met for your alignment to switch.
Anyone else have any thoughts with a crosstab field?


Posted By: ehy01
Date Posted: 30 Jan 2009 at 2:55am
Thanks DBlank!!!
 
Anyone else?
 


Posted By: DBlank
Date Posted: 30 Jan 2009 at 9:37am
One more thing you can try.
Click on the field that you are trying to change the text from. The field name will appear int he lower left hand corner of your crystal screen. Use that as a reference to know what field you are conditionally using and then put it into the formula.
Not sure it will work but it is worth a try.


Posted By: ehy01
Date Posted: 30 Jan 2009 at 10:19am
Nothing...Cry
 
This is the formula, that i put in the cell's of Cross Tab:
If IsNumeric(CurrentFieldValue) = True then
    crRightAligned
Else
    crLeftAligned
 
Work's 100%!!!
 
There is no way, to put another command in this code to align the "Column Name"?



Print Page | Close Window