if statement or if satement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

if statement or if satement

#1 Post by goodywp » 18 Dec 2023 15:53

Hi all,
I got a struggle of this two if statement while I try to add another condition on the previous code.
Original code is as below:

Code: Select all

	if defined RDL_TYPE_NAME (
		call:UpCase RDL_TYPE_NAME
		IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" (
			ECHO Skipping !RDL_TYPE_NAME!
			set RDL_TYPE_NAME=
			goto :endOfProcessing
		
	) else (
		call:ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
		call:ClearBeforeBreak "error"
		set /A ERRORC=31
		goto :exit	
	)
)
Now I try to add another or if statement IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!"
as below

Code: Select all

	if defined RDL_TYPE_NAME (
		call:UpCase RDL_TYPE_NAME
		IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" or IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!" (
			ECHO Skipping !RDL_TYPE_NAME!
			set RDL_TYPE_NAME=
			goto :endOfProcessing
		
	) else (
		call:ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
		call:ClearBeforeBreak "error"
		set /A ERRORC=31
		goto :exit	
	)
)
I tried both or, | none is working frome above code

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: if statement or if satement

#2 Post by Squashman » 18 Dec 2023 18:46

When you read the help file for the IF command where did it show usage for using a PIPE or OR?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: if statement or if satement

#3 Post by Aacini » 18 Dec 2023 19:16

Your code is wrong, not because the way of write that condition, but because the logic of such a condition. There are 3 possible results:
  1. The value of RDL_TYPE_NAME is equal to !RDL_TYPE_NAME:KIA=!, so is NOT equal to !RDL_TYPE_NAME:TKI=! and hence the IF is executed.
  2. The value of RDL_TYPE_NAME is equal to !RDL_TYPE_NAME:TKI=!, so is NOT equal to !RDL_TYPE_NAME:KIA=! and hence the IF is executed.
  3. The value of RDL_TYPE_NAME is not anyone of two values, so the IF is executed.
So, as you write your desired OR condition, don't matters the value of RDL_TYPE_NAME: the IF is always executed...

Antonio

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: if statement or if satement

#4 Post by Batcher » 18 Dec 2023 19:55

Code: Select all

if defined RDL_TYPE_NAME (
    call :UpCase RDL_TYPE_NAME
    if not "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" (
        echo Skipping !RDL_TYPE_NAME!
        set RDL_TYPE_NAME=
        goto :endOfProcessing
    ) else if not "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!" (
        echo Skipping !RDL_TYPE_NAME!
        set RDL_TYPE_NAME=
        goto :endOfProcessing
    ) else (
        call :ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
        call :ClearBeforeBreak "error"
        set /a ERRORC=31
        goto :exit
    )
)

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: if statement or if satement

#5 Post by goodywp » 19 Dec 2023 10:41

Thanks Batcher!
It is great!

Post Reply