Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Need Help with Record Selection Formula Post Reply Post New Topic
Page  of 2 Next >>
Author Message
JFKjr
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 7
Quote JFKjr Replybullet Topic: Need Help with Record Selection Formula
    Posted: 06 Aug 2009 at 8:40am
Hello Everyone,
 
I am trying to create a record selection formula which loops through all the selected values in the parameter list and checks whether the parameter values starts with "P-" string.
 
But, it seems the record selection does not support for loop.
 
//Not Working with for loop
 
NumberVar Limit := UBound({?Enter Vendor});
Numbervar Indx ;
 
For Indx := 1 To Limit Do
(
  local StringVar Txt := ToText({?Enter Vendor}[Indx]);
  if Txt startswith "P-" Then Txt := Mid (Txt, 3) ;
  {vendor.name} = Txt
);
 
//Working if I select a particular parameter value
 
if {?Enter Vendor}[1] startswith "P-" Then {vendor.name} = Mid ({?Enter Vendor}[1], 3)
 
Not sure how to check the string against all selected parameter values. Your help will be greatly appreciated. Thanks a million in advance.


Edited by JFKjr - 06 Aug 2009 at 8:50am
IP IP Logged
gavsmith
Newbie
Newbie


Joined: 06 Aug 2009
Online Status: Offline
Posts: 10
Quote gavsmith Replybullet Posted: 06 Aug 2009 at 8:55am
Not something I've tried but will it allow you to change the parameter values in the formula i.e.

NumberVar Limit := UBound({?Enter Vendor});
Numbervar Indx ;
 
For Indx := 1 To Limit Do
(
  local StringVar Txt := ToText({?Enter Vendor}[Indx]);
  if Txt startswith "P-" Then {?Enter Vendor}[Indx] := Mid (Txt, 3) ;
);
{vendor.name} in [{?Enter Vendor}]

Just an idea sorry if it doesn't help

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2009 at 8:59am

So you have a param that allows for multiple values to be selected and if a selection begins with "P" then you want it return when matching first 3 characters otherwise where it is an exact match?

If left({?Enter Vendor},1)="P" then left({?Enter Vendor},3)=left(vendor.name,3) else {?Enter Vendor}={vendor.name}
 
Place it in your select statement and it will run through the array of selected items in the param
IP IP Logged
JFKjr
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 7
Quote JFKjr Replybullet Posted: 06 Aug 2009 at 9:10am

Thanks for the reply, gavsmith.

Yes, I am able to change the parameter value and pass it to the database if I use a single parameter value in record selection formula editor. 

for ex:

//Working if I select a particular parameter value
if {?Enter Vendor}[1] startswith "P-" Then {vendor.name} = Mid ({?Enter Vendor}[1], 3)

But unable to loop through all the selected parameter values.
 
I have tested your code, it is generating the following error:
"The array must be subscripted"

Any suggestions?




Edited by JFKjr - 06 Aug 2009 at 9:12am
IP IP Logged
gavsmith
Newbie
Newbie


Joined: 06 Aug 2009
Online Status: Offline
Posts: 10
Quote gavsmith Replybullet Posted: 06 Aug 2009 at 9:11am
Originally posted by DBlank

So you have a param that allows for multiple values to be selected and if a selection begins with "P" then you want it return when matching first 3 characters otherwise where it is an exact match?

If left({?Enter Vendor},1)="P" then left({?Enter Vendor},3)=left(vendor.name,3) else {?Enter Vendor}={vendor.name}
 
Place it in your select statement and it will run through the array of selected items in the param


This looks much easier... only I think it should be more like:

If left({?Enter Vendor},2)="P-" then Mid({?Enter Vendor},3)={vendor.name} else {?Enter Vendor}={vendor.name}

hope that helps
IP IP Logged
JFKjr
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 7
Quote JFKjr Replybullet Posted: 06 Aug 2009 at 9:21am
Hello DBlank, thanks for the reply.
 
I am newbie to crystal reports. Sorry, if I haven't followed your reply correctly.
 
I placed the following code in record selection formula and it is throwing "The array must be subscripted" error.
 
code:
 
If left({?Enter Vendor},2)="P-" then Mid({?Enter Vendor},3)={vendor.name} else {?Enter Vendor}={vendor.name
 
What do you mean by place it in select statement? How can I do this?
 
Sorry for your inconvenience. Your help will be greatly appreciated. Thanks.
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2009 at 9:43am
Sorry, my mistake. I have been testing this out and my suggested process is not working...
I could swear I have done that before without having to handle the array differently.
YOu could use a command to trim that data out and then create your param dynamically from teh command field and select from that.
MIght be easier but not sure about performance
IP IP Logged
JFKjr
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 7
Quote JFKjr Replybullet Posted: 06 Aug 2009 at 10:14am

Hello DBlank,

let me briefly explain my situation.

I want to allow users to select the vendor names that start with "P-" in the parameter screen.

But, when they click OK button, I would like to get the vendor data from the database without "P-" in the selected vendor names.
 
Any ideas on how to implement the above scenario?  Let me know if I confused you.
 
Thanks.


Edited by JFKjr - 06 Aug 2009 at 10:17am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2009 at 10:47am

Where are these values coming from? In the DB or did you just create a list of vendors and toss "P-" in front of the exsiting data?

If not how is that field linked to Vendors list in the DB structure?

Edited by DBlank - 06 Aug 2009 at 10:47am
IP IP Logged
JFKjr
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 7
Quote JFKjr Replybullet Posted: 06 Aug 2009 at 11:10am

FYI, I created a command and added "P-" in front of the existing data.

Anyhow, I solved the issue :). Here is the solution:
 
1. I created the following formula:
 
//GetVendors formula
 
NumberVar Limit := UBound({?Enter Vendor});
Numbervar Indx ;
StringVar Msg;
For Indx := 1 To Limit Do
(
  local StringVar Txt := ToText({?Enter Vendor}[Indx]);
 
  if Txt startswith "P-" Then Txt := Mid (Txt, 3) ;
  Msg := Msg + Txt + ","
);
Msg
 
2. Added the following code to record selection formula:
 
Stringvar array myVendor:=split({@GetVendors},",");
{vendor.name} = myVendor
 
Boom! I am able to :
 
1. get the vendor data from the database for all the selected parameter values.
 
2. trim the vendor name without "P-" and pass it to the database.
 
Anyway, thanks for all your help :)
 
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.