| Author |
Message |
honda
Newbie
Joined: 09 Apr 2012
Online Status: Offline
Posts: 6
|

Topic: Pass parameter to formula Posted: 08 May 2012 at 7:59am |
|
Can I pass parameter to a formula in Crystal Report 2008 or any latest version.
I have about 5 different date fields all in numeric format. I want to format them into proper date format. I want to write one formula which accepts numeric date as parameter and returns the proper format of that date.
Edited by honda - 09 May 2012 at 9:16am
|
IP Logged |
|
|
|
LynnB
Newbie
Joined: 08 May 2012
Online Status: Offline
Posts: 15
|

Posted: 08 May 2012 at 8:09pm |
|
Hi, Yes you can pass parameters to a formula.
Simply pick up the parameter from your reports field list when you are creating the formula syntax.
Lynn.
|
IP Logged |
|
honda
Newbie
Joined: 09 Apr 2012
Online Status: Offline
Posts: 6
|

Posted: 09 May 2012 at 4:58am |
|
I think this might not be what I asked for. I know I can use my fields in the formula, my question is passing that field at the time of use in the report.
Example:
Date1, Date2, Date3 are my fields
format_date is my formula
Usually I would drage Date1, Date2 to the report when I want to display it. What I want is drage the formula to cyrstal report and provide it with the data which I want to format. So that I way I dont need 3 formula but one which will fix all my date formatting depending on what I pass to it when I use it in the report.
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|

Posted: 09 May 2012 at 5:17am |
|
I'm not quite sure I understand what it is you want exactly. But if I understand correctly, you have 3 formula's, all formatting the date in a different way. Depending on the data you want to use 1 of these formula's?
In this case, create a formula like:
if (criteria1) then Date1
else if (criteria2) then Date2
else if (criteria3) then Date3
|
IP Logged |
|
honda
Newbie
Joined: 09 Apr 2012
Online Status: Offline
Posts: 6
|

Posted: 09 May 2012 at 8:07am |
|
Not Exactly. Lets say I have 10 date fields all in numeric format. I want to format them in proper date format.
I want to write formula which accepts a parameter and format the date for me.
Normally if I want to display a field data, I will simply drag it to where I want to display it but now I want to drag my formula to the report and provide it with a parameter in this case date1 or date2 etc so it returns the correct format of the date, does not matter which field I pass to it.
Example: I write a formula which which takes a parmeter of Dat1 type, I drag it on crystal report and provide the parameter run time, which date I want to format. It does the formatting for me. So that way I dont have to write 10 formulas for 10 different dates, all in same format but are different fields in the database.
I hope I made it clear this time. I want to pass parameter to the formula, just like I would pass a parameter to a function. If I drag that function on report, this function would require a parameter, i provide that and the function does my job. In this case just formatting.
Edited by honda - 09 May 2012 at 8:10am
|
IP Logged |
|
LynnB
Newbie
Joined: 08 May 2012
Online Status: Offline
Posts: 15
|

Posted: 09 May 2012 at 12:12pm |
|
It is still not clean what you are asking for.
Are you wanting to use the parameter to define the date format?
Can you provide a simple example of your code?
|
IP Logged |
|
kostya1122
Senior Member
Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
|

Posted: 09 May 2012 at 1:21pm |
|
so basically you're asking for a formula that converts your numeric field into proper date. you forgot to show your numeric field format like yyyymmdd or something, without that its hard to help you.=)
|
IP Logged |
|
honda
Newbie
Joined: 09 Apr 2012
Online Status: Offline
Posts: 6
|

Posted: 10 May 2012 at 3:14am |
|
My date is a number which stores data in YYYYMMDD format
End Date = 20120115 (yyyymmdd)
I created this formula field which converts this number into proper date format
Local StringVar y; y := CSTR({?end date}, 0, ''); MID(y,1,4) + '-' + MID(y,5,2) + '-' + MID(y,7,2)
As you can see my formula above take a {?end date} field. What I want to do is pass this a parameter so I dont have to creat 10 formula fields for 10 different date fields. All my dates are numeric an in YYYYMMDD format.
Edited by honda - 10 May 2012 at 3:14am
|
IP Logged |
|
|
|