Click to See Complete Forum and Search --> : Newbie Question


bobbabuoy
November 7th, 2008, 05:13 AM
I am new to crystal reports but I have a pretty solid sql background as well as vb6 and asp. Here is my question:

how do I get a formula field to return a number, and then increment itself by one if a date falls in a certain range? Here is what I want to do in a formula field:

If {RegistrationMaster.Use Date} >= {@BegDate} and {RegistrationMaster.Use Date} <= {@EndDate} Then increment the value by of this field by one

Thanks!

Ned Pepper
November 7th, 2008, 10:22 AM
I'm not sure I fully understand how your data is held but I hope the follow helps. Since you have a background in VB I will address in basic syntax. You can change the syntax in the formula editor by selecting ctrl+t. (Perhaps just knowing you can use basic in Crystal is all you really need)

if you just want to add a day to your "Use Date" field


If {RegistrationMaster.Use Date} >= {@BegDate} _
and {RegistrationMaster.Use Date} <= {@EndDate} then
Formula = dateadd('d', 1, {RegistrationMaster.Use Date}
else
Formula = {RegistrationMaster.Use Date}
end if


you can use variables to persist the incrementation, depending on how the data is stored. I use a shared variable here. Shared and global variables are similar, check the help files...

shared bTest as boolean
shared dOutPutDate as Date

if bTest = False then
dOutPutDate = {RegistrationMaster.Use Date}
bTest = True
end if

If {RegistrationMaster.Use Date} >= {@BegDate} _
and {RegistrationMaster.Use Date} <= {@EndDate} then
dOutPutDate = dateadd('d', 1, {RegistrationMaster.Use Date}
end if

formula = dOutPutDate