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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I change a text object from a formula?

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hi All,
I'm using Crystal Reports 10.

I there a way to change the text of a text object through a formula? I have 31 text objects whose text must change dynamically. What I have in mind is to create a formula that changes the text of all text objects as need be. How do I access the text object from the formula?

Thanks.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
By definition, these cannot be text object. They also need to be formulas. For example:

If <<Condition1>> then "Text 1" else
if <<Condition2>> then "Text 2" else
.....


Continue this type of logic as needed.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
Text objects are simply that, text.

If you need conditionals to generate output, then use a formula, however you can drop formulas into text objects if that helps.

-k
 
Thanks dgillz.

I find it strange that I could change the text of Crystal Reports text objects from .NET and not from within Crystal Reports itself. From .NET code, for example, assumming that rprt is a Crystal Reports object, I could do something like this:

[tt]rprt.ReportDefinition.ReportObjects["Text1"].Text = "hi";[/tt]

I really don't see the reason why this wouldn't be possible from Crystal Reports itself, if it can be done from .NET code. Are you sure I have to create 31 formulas?

Thanks.

JC


_________________________________________________
To get the best response to a question, read faq222-2244.
 
Hi,
What you coded:

rprt.ReportDefinition.ReportObjects["Text1"].Text = "hi";

IS a formula.....If I read it correctly,it would only change the text object named Text1..How is that different than what has been posted for your issue?





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Thanks for your replies synapsevampire and Turkbear,

Turkbear,
I think I may be missing the point.

I want to create ONE formula in my report... (just ONE) formula, which will change the text displayed by 31 different text objects.

The .NET code I posted is ONE function, and there, I could loop through all 31 text objects and change their text based on my business rules.

What has been posted here suggests that, instead of creating 31 text objects and ONE formula, I must create 31 formulas and use them in place of the text objects. Because I'm assumming that 31 formulas will take more processing time than one (with 31 text objects), I thought it made sense to use the text objects instead.

Am I missing something?

Thanks.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Hi,
Maybe...

If your code in .NET loops through each Text object, then it executes 31 times...Since the Name of the object needs to be changed and ,I assume, you are not setting all 31 to the same value.


So, it should not be much different if you have 31 formulas that change depending on some business rule triggered by a passed value.BUT:
Personally, I would create an array of 31 default text values and use each element of that array in separate formulas to display the desired text..

That way I can have another formula that, depending on the business rule parameter passed to it, will change each element ( by looping thru them) of that array, thus making the text displayed dynamic ...




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Why don't you provide a sample of the 31 different text objects and explain what conditions might apply?

-LB
 
Hi,
My idea of creating an array seemed easy to describe, but turned out to be difficult in practice..I cannot seem to get Crystal to allow me to create the array for use by the report..Could be my lack of experience in doing that, but it seemed like a simple thing that should have been something like creating a formula as:

Shared StringVariable array Textlist := ["texta","Textb","Textc"]

But Crystal says the result of a formula cannot be an array,so How can I create an array without using a formula?






[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Thanks guys... lol

LB,
What I need to do is quite simple, really. I have a report that displays data grouped by month. Each page of the report must contain (on the page header) the month name and 31 labels, one for each day of the month. The lables should say "M" for Monday, "T" for Tuesday, and so on (just like in a calendar, except that all days of the month will be displayed horizontally). Thus, at least 28 labels (for February) should always be visible in the page header. Below each label, the actual day of the month, such as 1, 2, 3, etc, should also be displayed so that the user will know that Junly 26, 2005, for example, is a Tuesday.

What I thought I could do was simply create 31 text objects (named txtDay1, txtDay2, txtDay3, etc) and have one formula that would run on the page header and, depending on the month [and year], would update the text objects to make them display "M", "T", "W", and so on.

I didn't want to create 31 different formulas (one for each day), because I assumed it would degrade performance. However, it seems that text objects cannot be updated from formulas, and I just found that to be silly, given that they can indeed be edited from .NET code.

Thanks.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Turkbear,
You can create an array in a formula, but it cannot be the last statement in such formula because Crystal Reports formulas return the last statement in them. Update your formula so that it says this:
Code:
[tt]Shared StringVariable array Textlist := ["texta","Textb","Textc"]
[red]1;[/red][/tt]

This way, 1 will be returned, not the array, and Crystal Reports will be happy. With, or without an array though, it seems there's no escape from having to write 31 formulas for what I need. I know how to do that... I just didn't want to do it.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
They can also be editied from VB, or C or many other languages because you're going through an API, within Crystal itself a TEXT object istreated as text.

The fact that you successfully made the decision to not use formulas while using .net has no nearing on what a text object is or it's intent within Crystal.

You could have used loops to construct formula names within .net as well and populated them.

Again, a text object is intended to display text, as in a column heading or a label for some entity.

-k
 
Turk:

Shared StringVariable array Textlist := ["texta","Textb","Textc"];
Textlist[1]

Where 1 will deomnstrate it's first value.

Use something like the following to join them back up:

join(Textlist,",")

-k

 
Hi,
Thanks, Synapse..One more question about that ( Right, that's what they all say..[smile])
Can I use a subsequent formula to change the elements in Testlist?

I could not find a way to just create the array as a shared, dynamically modifyable, object in the report ( to avoid having to use a formula which needs to have only 1 element , not an entire array, as its return value) .




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
You could dynamically determine the headings by doing the following, which still entails creating 32 formulas, but 31 can be pasted and edited quickly, and won't need to be changed in the future. This assumes your report is grouped on date monthly and that you have formatted the group footer with a new page after.

Create a formula:

//{@firstdayofmo} to be placed in a page header_a section:
whileprintingrecords;
stringvar array wkday := ["Su","M","T","W","Th","F","Sa",
"Su","M","T","W","Th","F","Sa",
"Su","M","T","W","Th","F","Sa",
"Su","M","T","W","Th","F","Sa",
"Su","M","T","W","Th","F","Sa",
"Su","M","T","W","Th","F","Sa"];
numbervar x := dayofweek(date(year({table.date}),month({table.date}),01));

Then create 31 formulas like the following, to be placed in the page header_b section:

//{@day1}:
whileprintingrecords;
stringvar array wkday;
numbervar x;
wkday[x] + chr(13) + "1";

//{@day2}:
whileprintingrecords;
stringvar array wkday;
numbervar x;
wkday[x+1] + chr(13) + "2";

//{@day31}:
whileprintingrecords;
stringvar array wkday;
numbervar x;
wkday[x+30] + chr(13) + "31";

Format each of the 31 formulas to "can grow". Also use field suppression to conditionally suppress the formula for {@day29}:

day(dateserial(year({table.date}),month({table.date})+1,01)-1 = 28

Suppress {@day30} with:
day(dateserial(year({table.date}),month({table.date})+1,01)-1 = 29

Suppress {@day31} with:
month({table.date}) in [2,4,6,9,11]

This will result in the correct day name for the first day of the month, followed in sequence by the daynames for the rest of the month, with the day number displayed below.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top