Link to home
Start Free TrialLog in
Avatar of elwayisgod
elwayisgodFlag for United States of America

asked on

Set variable with 'OR' logic possible?

I need to set a variable based on two conditions.  If either of the conditions are true then set the variable one way, if neither are true then set the variable another way.

Basically I'm playing with changing the 'theday' and the 'DATE_dow' variables and running.  However it's not working.  The logic is:

If %theday% LEQ 12 OR %DATE_dow% then excludeDirsDistr=Distr,Distrstg,DistrDEC,
else if neither of those are true then excludeDirsDistr=

I'm obviously not nesting this correctly or the logic above I can't accomplish like this.  Played with all kinds of combinations and not working.  Trying to avoid many 'IF' lines in order if possible...

set theday=11
set DATE_dow=Thu
set excludeDirsDistr=Distr,Distrstg,DistrDEC,
if not %theday% LEQ 12 if not %DATE_dow%==Wed set excludeDirsDistr=

Open in new window

Avatar of elwayisgod
elwayisgod
Flag of United States of America image

ASKER

Do I have to do it in three lines?  This works but didn't think it's ideal:

if %theday% LEQ 12 if %DATE_dow%==Wed set excludeDirsDistr=
if not %theday% LEQ 12 if %DATE_dow%==Wed set excludeDirsDistr=
if not %theday% LEQ 12 if not %DATE_dow%==Wed set excludeDirsDistr=Distr,Distrstg,DistrDEC,

Open in new window

Avatar of oBdA
oBdA

I'd do it like this:
set theday=11
set DATE_dow=Thu
set excludeList=Distr,Distrstg,DistrDEC,

set excludeDirsDistr=
if %theday% LEQ 12 set excludeDirsDistr=%excludeList%
if /i %DATE_dow%==Wed set excludeDirsDistr=%excludeList%

Open in new window

If %theday% LEQ to 12 then it needs to be empty.  Above sets it to Distr,Distrstg,DistrDEC...
That's what you wanted in your question:
If %theday% LEQ 12 OR %DATE_dow% then excludeDirsDistr=Distr,Distrstg,DistrDEC,
So what is it exactly you want (especially the condition that's missing for "%DATE_dow%"?

Anyway, whatever your goal is, the method remains the same if you want to combine several conditions with an "or":
1. You set the "false" as default value
2. You add one line per "true" condition where you set the "true" value.
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My bad had a typo:

If %theday% LEQ 12 OR %DATE_dow% ==Wed then excludeDirsDistr=Distr,Distrstg,DistrDEC,
else if neither of those are true then excludeDirsDistr=

Sorry about that.  If I have to have multiple lines of IF then this will work as there are four different combinations.  Just ugly.

set excludeDirsDistr=
if %theday% LEQ 12 if %DATE_dow%==Wed set excludeDirsDistr=
if %theday% LEQ 12 if not %DATE_dow%==Wed set excludeDirsDistr= 
if not %theday% LEQ 12 if %DATE_dow%==Wed set excludeDirsDistr=
if not %theday% LEQ 12 if not %DATE_dow%==Wed set excludeDirsDistr=Distr,Distrstg,DistrDEC,

Open in new window

@BP,

I think yours combines my 4 into two.... :)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Going with this as it covers all 4 possibilities:

set excludeDirsDistr=Distr,Distrstg,DistrDEC,
if %theday% LEQ 12 set excludeDirsDistr=
if %DATE_dow% EQU Wed set excludeDirsDistr=

Open in new window

Thanks for clarification. I got caught up on the 'if not' and it threw me for loop :)
That is the exact opposite of
If %theday% LEQ 12 OR %DATE_dow% ==Wed then excludeDirsDistr=Distr,Distrstg,DistrDEC,