Link to home
Start Free TrialLog in
Avatar of SETP
SETP

asked on

Passing long string to parameter field

Hi

I have a Crystal Report (the one bundled with Visual Studio .NET 2003), that has a couple of parameter fields (no database stuff) and is working perfectly. I'm populating the parameter fields in runtime from VB.NET 2003. But I just realized that for one of the text parameter fields, if I pass it more than a certain amount of characters (I think 256 characters) it throws the following exception:

An unhandled exception of type 'System.ArgumentException' occurred in crystaldecisions.crystalreports.engine.dll

Additional information: Value does not fall within the expected range.

Any idea how to overcome this problem? I have to send the parameter about a page worth of text.

Thanks
Avatar of SETP
SETP

ASKER

OK, just checked properly. It bombs when I send it more than 254 characters (i.e. 255 or more characters)
Text objects prior to version 9 (.NET 2003 is based on V9) had a limit of 255 characters. There may be a hotfix avaialable to fix this http://support.businessobjects.com/communityCS/FilesAndUpdates/crnet11win_en.zip.asp

As a matter of interest what are you using this paramater for do you really need to filter on a full page of text ?

Gary
Avatar of SETP

ASKER

Thanks for the reply. I installed the latest hotfix but still has that problem. What I'm doing is basically as follows:

The user types a letter in a standard windows text box and clicks print. That launches a form with a CrystalReportViewer on it, which loads the report with a company logo and footer, some other data (client address, reference number, etc) and then in the main section the actual letter. This then gets printed and posted (or e-mailed or faxed)
As far as I know there is no fix for this issue prior to version 9.  As a suggestion you might want to take what the user has typed and write it out to a database field then launch your CRViewer to load the report that pulls the data you've just written from a db table.  This will get you around the length of the parameter problem.

(of course I'd consider using MS Word instead of Crystal for this if you have that option).
I personally don't use .NET so can't try this out, but I would suspect CR is getting upset with the amount of data ina  paramater field. Instead of using a paramater field try inserting a formula field or Text object and set tthe text value of this at run time.

Gary



Avatar of SETP

ASKER

Any ideas how can I set the text value of a Text or Formula object at run time? I only know how to set the value of a Parameter field at runtime. Can this even be done?
Avatar of Mike McCracken
I agree.  Crystal changed it so text fields longer than 254 characters could be used in formulas but I suspect there may still be a limit on parameters.

Formulas can be set in a manner similar to parameters.

mlmcc
Here's the code to set a formula at run time:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

'Above the statement, "#Region ... ", add the following lines of code.

Dim crReport as New CrystalReport1()

'After the call to InitializeComponent() in the form's constructor, type the following code
'to set the formula field

crReport.DataDefinition.FormulaFields.Item("FormulaName").Text = "({Customer.Last Year's Sales} * 5) / 3"

'Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReport

(from: http://support.businessobjects.com/library/kbase/articles/c2010354.asp )
Avatar of SETP

ASKER

But can I add just text instead of a formula? Because it gives me an error:

========================================
Error in formula <Message>
'This is a test 1234567890'
The remaining text does not appear to be part of the formula
========================================

This is the code I used:

Dim crFormulaFieldDefinitions As FormulaFieldDefinitions
Dim crFormulaFieldDefinition As FormulaFieldDefinition

crFormulaFieldDefinitions = CrystalReport1.DataDefinition.FormulaFields
crFormulaFieldDefinition = crFormulaFieldDefinitions.Item("Message")
crFormulaFieldDefinition.Text = "This is a test 1234567890"
Try :-

crFormulaFieldDefinition.Text = "'This is a test 1234567890'"

Gary
That's it.  You need to include the single quotes because what's inside your double-quotes should be the same text you'd enter from the crystal designer.
Avatar of SETP

ASKER

Thanks for all your help guys. Well, that solved the 254 character max length problem, but now it brings another problem. You can't have carriage returns in the string that you pass it. So the user would have to type a letter as one long paragraphs with no blank lines! Aaaagh!!! Just when I though I had it! :( Oh well, I guess I can write the data to a database and then pass it to the report. But before I do, is it possible to change the text of a plain Text Object in the report? Can I get a handle to it?

Thanks
Avatar of SETP

ASKER

I saw that the Formula field in Crystal Reports allows you to insert, well, formulas. And there is one String formula which looks like this:

     Replace (inputString, findString, replaceString)

I've never used formulas before, so I'm a bit syuck here, but could I not maybe use this formula to replace all events of a string, for example, '===' and replace it with carriage returns? Then from my VB app, I will replace all carriage returns with "===".

Does anyone think that might work? If so, how can I use these formulas?

Thanks a million
That sounds lie a good idea, you would use the replace() function like this :-

Replace ('This is how to===place carriage returns===in a text object','===' ,chr(13))

this should display

This is how to
place carriage returns
in a text object

Gary
Avatar of SETP

ASKER

OK, is the example you gave me above what must be inserted into the formula field in the Crystal Report? Or is it something I must do in my VB code? Because I must replace the hard-coded sample sentence in the example above with the the text that I'm sending the formula field. How is this done? Sorry - I've got almost zero Crystal Report experience (and I'm sure it shows)

Thanks
ASKER CERTIFIED SOLUTION
Avatar of GJParker
GJParker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another option is to replace the === with <BR> and make sure you've formatted the formula field to use HTML text interpretation.  The advantage to this approach is that it allows you to also use other HTML formatting tags if you want to use bold text, italics, etc.  If you have no interest in ever doing that then stick with chr(13).
Avatar of SETP

ASKER

Thanks guys. You really helped me a lot. It was difficult deciding who to give the points to, but unfortunately I could only choose one of you. But both really helped me a lot.

Regards
Glad I could help

I believe it is possible to split points between people.

Gary
Yes, splitting is possible.

Before you accept the answer, there is a link below the last comment and before the new comment block to SPLIT POINTS.  When you click that you can allocate the points to any or even all the comments that helped.

If you wish to do that submit a request in the Community Support forum to reopen this question.

mlmcc