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

Extract certain information from a string

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I am looking to achieve the following in Crystal Reports 9.

I have a string parameter set up in which the user enters values such as >28000, <28000, 28000....

What I want to do is take the value they enter and split the < or > and the number into two seperate parameters. One would hold the < or > symbol and the other would hold the number.... this would then be applied to the report through a formula.
If no < or > sign has been entered then just the number will be passed to the number parameter.

I hope I've explained this ok!

Thanks in advance,

Woody
 
I don't believe you will be able to use the entered symbol directly in any formula.
You will have to test the first character and then follow up with additional code that performs the test you want.

Something like... (totally untested)

numbervar myvalue;
if left({?myparam},1) = "<" then
(
myvalue:= val(mid({?myparam},2));
if {mytable.myfield}< myvalue then
( .....whatever)
else
(....whatever)
)
else if left({?myparam},1) = ">" then
(
myvalue:= val(mid({?myparam},2));
if {mytable.myfield}> myvalue then
( .....whatever)
else
(....whatever)
)
else
(
myvalue:= val(myparam});
if {mytable.myfield}= myvalue then
( .....whatever)
else
(....whatever)
)

I don't know how you stop the user entering rubbish though.
In my opinion you should be using two paramaeters; one for the operator - which you can then restrict to <>= and one for the number.





 
And that's what I suggested in thread767-952936:

if {?Sign} = "<" then
tonumber({table.string}) < {?Amt} else
if {?Sign} = ">" then
tonumber({table.string}) > {?Amt}

You could amend this to:

if ({?Sign} = "=" then
tonumber({table.string}) = {?Amt} else
if {?Sign} = "<" then
tonumber({table.string}) < {?Amt} else
if {?Sign} = ">" then
tonumber({table.string}) > {?Amt}

You would set up "=" as the topmost selection for the {?Sign} parm, so that if no selection was made, "=" would be the default.

If you really must use only one parameter, then you could simplify lupins' suggestion to:

if isnumeric(left({?parm},1)) then
{table.amt} = val({?parm}) else
if left({?parm},1) = "<" then
{table.amt} < val(mid({?parm},2)) else
if left({?parm},1) = ">" then
{table.amt} > val(mid({?parm},2)) else
{table.amt} = 0 //or {table.amt} <> 0, depending on what
//you want returned when people incorrectly enter data

-LB
 
Hi again,

Thanks both for your help....

LB, when I use the 2nd example you've given me, using just one parameter, I get the following error....

'A String is Required Here' and it highlights the following code:

val({?parm})

Any ideas?

Woody
 
I forgot that the field you were comparing to the parameter was also a string. So change the formula to:

if isnumeric(left({?parm},1)) then
tonumber({table.string}) = val({?parm}) else
if left({?parm},1) = "<" then
tonumber({table.string}) < val(mid({?parm},2)) else
if left({?parm},1) = ">" then
tonumber({table.string}) > val(mid({?parm},2)) else
tonumber({table.string}) = 0

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top