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

Need help on what should be a simple formula 1

Status
Not open for further replies.

NewB2007

Technical User
Feb 25, 2008
42
US
Here is what I believe that I need but I'm not for sure. More or less the question that I have is how to loop through a multiple selection parameter. Please read through the comments and see if you can make sense of what I am trying to say.
(
if {?Loctype filter} = '*' then
{RM_MAINT.LOCTYPE} like {?Loctype filter}
// Need all that fall under this criteria
and {EQUIP.ACTIVE_IN_DISP} = 'True'
and {TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'
else
{RM_MAINT.LOCTYPE} = {?Loctype filter}
//For Each parameter selection that is selected I need
//to make sure that it is still "True".
//The users can select multiple criteria. I know that I
//a loop of some kind. But I don't know how to loop
//through the selected criteria in crystal XI.
)

Thanks ahead of time!
 
IF (test) THEN (action) ELSE (alternative)

Your second line should start with IF, assuming it is an extra test. Or it should have an AND, to make it part of a complete set of tests

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
This is what I am thinking that I will need. But will it continue if say 'test1' if fulfill? because the users selection could fulfill say 'test1' and 'test3'? Will it break out after 'test1'. I want it to check all three and then do only the ones that are true or completed.

IF (test1) THEN
(action1)
ELSE
IF (test2) THEN
(action2)
ELSE
(action3)
 
This works...

if {?Loctype filter} = '*' then
{RM_MAINT.LOCTYPE} like {?Loctype filter}
else
{RM_MAINT.LOCTYPE} = {?Loctype filter}
and
if {?Loctype filter} = 'PU' then
{PUNIT.ACTIVE_WHERE} = 'D'

When I try and add the rest of the formula it stops working.
This doesn't...

if {?Loctype filter} = '*' then
{RM_MAINT.LOCTYPE} like {?Loctype filter}
else
{RM_MAINT.LOCTYPE} = {?Loctype filter}
and
if {?Loctype filter} = 'PU' then
{PUNIT.ACTIVE_WHERE} = 'D'
// From here down is all that is add new.
else
if {?Loctype filter} = 'EQ' then
{EQUIP.ACTIVE_IN_DISP} = 'True'
else
if {?Loctype filter} = 'TR' then
{TRAILER.ACTIVE_IN_DISP} = 'True'

PLEASE HELP!!!!!!!!
 
I think you are looking for something like this

select {?Loctype filter}
case '*': {RM_MAINT.LOCTYPE} like {?Loctype filter}
case 'PU': {PUNIT.ACTIVE_WHERE} = 'D'
case 'EU': {EQUIP.ACTIVE_IN_DISP} = 'True'
case 'TR': {TRAILER.ACTIVE_IN_DISP} = 'True'
 
This is a good idea. But if case 'PU' is fulfilled will it continue on and check 'EU' and 'TR'? I tried what you put down but no data showed at all.
 
Your post is very unclear. Please explain what the selection formula should do.

-LB
 
If a user selects * then
{EQUIP.ACTIVE_IN_DISP} = 'True'
{TRAILER.ACTIVE_IN_DISP} = 'True'
{PUNIT.ACTIVE_WHERE} = 'D'

If a user selects 'PU' then only the PUNITS show on the report where
{PUNIT.ACTIVE_WHERE} = 'D'

But a user can select multiple possibilites. 'PU' and 'EQ' or 'PU' and 'TR' ... u get the picture. well I just try to do this simply like this

if X then
{EQUIP.ACTIVE_IN_DISP} = 'True'
and {TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'

else if Y then
{EQUIP.ACTIVE_IN_DISP} = 'True'
and {TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'

Doing this will always select what I want but this will not work. Nothing will show on the report. But if I do this then all works fine. it is when I add the extra statements into the mix I am not retreiving any data. and I KNOW that it is there.

if X then
{EQUIP.ACTIVE_IN_DISP} = 'True'
else if Y then
{EQUIP.ACTIVE_IN_DISP} = 'True'

Let me know if my rambling makes any sense


 
Try this:

(
(
{?Loctype filter} = '*' and
{EQUIP.ACTIVE_IN_DISP} = 'True' and
{TRAILER.ACTIVE_IN_DISP} = 'True' and
{PUNIT.ACTIVE_WHERE} = 'D'
) or
(
{?Loctype filter} = 'PU' and
{RM_MAINT.LOCTYPE} = {?Loctype filter} and
{PUNIT.ACTIVE_WHERE} = 'D'
) or
(
{?Loctype filter} = 'EQ' and
{RM_MAINT.LOCTYPE} = {?Loctype filter} and
{EQUIP.ACTIVE_IN_DISP} = 'True'
) or
(
{?Loctype filter} = 'TR' and
{RM_MAINT.LOCTYPE} = {?Loctype filter} and
{TRAILER.ACTIVE_IN_DISP} = 'True'
)
)

Not sure I have the conditions right, as they seem to have changed in different posts. Not sure you need the quotes around 'True' either, but I guess you would know.

-LB
 
In the normal usge of if-then-else operators the following tends to apply:

1) Usual if-then-else usage will check for each test before returning the action. If a record matches an earlier test then it will not be checked again against remaining tests.


e.g. If {field.1} = 4 then 'Blue' else If {field.2} = 7 then 'Green' Else 'Purple'

If a record had both {field.1} and {field.2} values then it would be displayed as 'Blue' (The first test which it matched).

As LB has posted above if you use parenthisis and the OR operator then you are seperately looking for each scenario and returning those records, this is simply to retreive these record sets where they match any of the grouped required criteria not to assign a distinct value to each record returned.

'J
 
I guess that I am doing a poor job of explaining what it is that I want to do. So I will give it one more try.

If a user select '*' then

{EQUIP.ACTIVE_IN_DISP} = 'True'
and {TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'


But if a user selects more than one selection from a parameter field then I want to loop through and do the following. The selection can be "PU", "EQ", "TR". And say the user selects "PU" and "TR" Then only do

{TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'

The problem that I am encountering is that if a user selects more than one from a parameter the report returns no data. The same goes for when a user selects all(*) to be returned. But if a user on selects on then it works fine.



 
My formula syntax should have worked for this.. Is this what you mean for conditions though?

(
(
{?Loctype filter} = '*' and
{EQUIP.ACTIVE_IN_DISP} = 'True' and
{TRAILER.ACTIVE_IN_DISP} = 'True' and
{PUNIT.ACTIVE_WHERE} = 'D'
) or
(
{?Loctype filter} in ['PU','EQ','TR'] and
TRAILER.ACTIVE_IN_DISP} = 'True'
and {PUNIT.ACTIVE_WHERE} = 'D'
)
)
 
I think something more like this, but I will fix this and give you one that enumerates through the multiple selection parameter {?Loctype filter} in a bit.

(
(
{?Loctype filter} = '*' and
{EQUIP.ACTIVE_IN_DISP} = 'True' and //EQ
{TRAILER.ACTIVE_IN_DISP} = 'True' and //TR
{PUNIT.ACTIVE_WHERE} = 'D' //PU
) or
(
'EQ' in {?Loctype filter} and 'TR' in {?Loctype filter}
{EQUIP.ACTIVE_IN_DISP} = 'True' and //EQ
{TRAILER.ACTIVE_IN_DISP} = 'True' //TR
)
) or
(
'PU' in {?Loctype filter} and 'TR' in {?Loctype filter}
{PUNIT.ACTIVE_WHERE} = 'D' and //PU
{TRAILER.ACTIVE_IN_DISP} = 'True' //TR
)
) or
(
'PU' in {?Loctype filter} and 'EQ' in {?Loctype filter}
{PUNIT.ACTIVE_WHERE} = 'D' and //PU
{EQUIP.ACTIVE_IN_DISP} = 'True' //EQ
)
)


 
Actually enumerating won't work, because if a enumerate through and concatenate to a string on every loop, then there is no way for me to take that string and then use it as a boolean statement. I was working on something like the following, but I will instead just add to the one I sent a bit ago.

stringVar s:="";
NumberVar x;

for x:=1 to count({?Loctype filter}) step +1 do
select {?Loctype filter}
case 'PU': s:=s+" and {PUNIT.ACTIVE_WHERE} = 'D'";
case 'EU': s:=s+" and {EQUIP.ACTIVE_IN_DISP} = 'True'";
case 'TR': s:=s+" and {TRAILER.ACTIVE_IN_DISP} = 'True'";
 
This should do it:

(
(
{?Loctype filter} = '*' and
{EQUIP.ACTIVE_IN_DISP} = 'True' and //EQ
{TRAILER.ACTIVE_IN_DISP} = 'True' and //TR
{PUNIT.ACTIVE_WHERE} = 'D' //PU
) or
(
'EQ' in {?Loctype filter} and 'TR' in {?Loctype filter}
{EQUIP.ACTIVE_IN_DISP} = 'True' and //EQ
{TRAILER.ACTIVE_IN_DISP} = 'True' //TR
)
) or
(
'PU' in {?Loctype filter} and 'TR' in {?Loctype filter}
{PUNIT.ACTIVE_WHERE} = 'D' and //PU
{TRAILER.ACTIVE_IN_DISP} = 'True' //TR
)
) or
(
'PU' in {?Loctype filter} and 'EQ' in {?Loctype filter}
{PUNIT.ACTIVE_WHERE} = 'D' and //PU
{EQUIP.ACTIVE_IN_DISP} = 'True' //EQ
)
) or
(
'PU' in {?Loctype filter}
{PUNIT.ACTIVE_WHERE} = 'D'//PU
)
) or
(
'EQ' in {?Loctype filter}
{EQUIP.ACTIVE_IN_DISP} = 'True' //EQ
)
) or
(
'TR' in {?Loctype filter}
{TRAILER.ACTIVE_IN_DISP} = 'True' //TR
)
)
 
You may have to change the third line from

{?Loctype filter} = '*' and

to

'*' in {?Loctype filter} and

since {?Loctype filter} is a multiselect
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top