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

Multiple Value Parameters with Mid Function

Status
Not open for further replies.

tmcain

Programmer
Jan 29, 2002
25
US
I have a report that uses a multiple value parameter. The report fields are dependent on matching an exact copy of only a part of the parameter. For example, the value selected for the parameter might be D12345667 StoreRoom. Records can't be retrieved using the whole value, only the 'D12345667' part of the param.
I have read that Crystal Reports treats multi-value params as arrays. For that reason, I can't simply use a mid function and set the field equal to the parameter in that way. I wondered if anyone knows how to get about this.

If you need further clarification, let me know.

I have tried various formulas, tried a control structure (For Next) and even got online at Seagate's website. They listed a file to download with a formula for solving this problem. BUT, I can't find the file anywhere on the website. I thought maybe there could be another workaround.

Thanks!
 
You can use the mid function. I know you can create a variable for the array subscript so if you use:

whileprintingrecords;
numbervar x:=1
mid({?param}[x],1,5)

will give you the first five characters of param[1]. You would just need to add this to a loop structure that will change the value of x, and retrieve each value in the parameter array.

I have a similar question I just posted, because I am having a problem writing the loop. If my solution helps, I will repost. In the mean time, maybe someone else can help.

Good luck.
 
This is the formula I have tried so far. I put this in the selection expert because we are selecting records for the whole report based on the first 8 characters of the parameter.

stringvar dept;
numbervar x:=0 ;
numbervar I;
for I:= 1 to x
do
dept:= mid({?Department}[x],1,5);
x:=x+1 ;
{TIDWOSUM.COST_CENTER_CHARGE}=dept

It isn't working.

If you can see what I am doing wrong, let me know.

Thanks
Tawnya
 
A couple things right off the bat.

1. When you say it isn't working, are you getting an error message or is it not selecting properly? I don't usually put these kind of formulas in the select expert, I tend to write a formula and then refernce the formula in the select expert (it's probably not any more than personal preference)

2. There may be a problem with the loop (understand I am lousy at them...) You initialize x:=0, so the first time through in the mid function you will be giving it a value of 0 places. Could this be a problem?

 
To question one, I don't get any data back. period.

For the third one, I started with a zero because I thought that sometimes arrays start at zero and then increment. I wasn't sure how CR does it. I guess I could try that.

I didn't think about simply referencing a formula in the selection expert.

Would there be a better loop for this other than the one I chose?

 
Tmcain,

Lets back up a bit- you might be making this too tough. You can create parameter fields with default values that include a value (what you could easily use in record selection formulas) and a description (what is needed for the user to understand what he/she is asking for).

If your report uses default values I think this is an option.

Let me know if you have any more questions. Software Support for Sage Mas90, Macola, Crystal Reports, Goldmine and MS Office
 
Can you separate your parameter default list into Code and Description, so they see both, but only pass the code?
Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ken-

Yes, when you create a parameter field AND its default values (this does not work without default values) you can create a parameter value and a description of the parameter value. Use your parameter field in your record selection formula like you normally do and only the value portion is evaluated in record selection formulas or any other logic for that matter. The description value is for diplay only for the user's benefit.

When you create your default values and add them to the list, there is a "Define Description" button to the right of that window. Enter the descriptions. By default when the user is prompted both the value and description are displayed, separated by a dash. In fact you can diplay description only and the user never sees that value(s) that will be used in your report logic.

Example
Dept Values-------Description
100 Engineering
200 Sales
300 Manufacturing

In the above case if the user picks the value (that the user sees) of 100-Engineering from the drop down list then they will get all records from the database that have a value of 100 in the department field.

The only drawback to this I have found it that when you place the parameter field on your report header, you get the value only and not the value and description. Ther emust be a way around this but I have yet to find it.

Does that answer your question? I have an example I can email you if you are interested.
Software Support for Sage Mas90, Macola, Crystal Reports, Goldmine and MS Office
 
Yes, we are in the process of adding descriptions to params now. It is just a mild headache when you have LOTS of fields to do this to. I was really hoping that there was a formula that would simply extract that info from the param for us.

Thanks
Tawnya
 
Tawnya-

I'm sure you've already though of this but if the value you need to extract is always the first X number of characters you can use the left() function.

Also, if the value is always the first word (word being defined as consecutive characters with no spaces) you can use the following formula to extract it:

left({?Parmfield},instr({?Parmfield}," ")-1)

Software Support for Sage Mas90, Macola, Crystal Reports, Goldmine and MS Office
 
Thanks, but yes I tried the left function first. I am getting the last of the fields done, but it looks like it will work when we move the rest of the field to the description line.

I appreciate your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top