Page 1 of 1

if statement or if satement

Posted: 18 Dec 2023 15:53
by goodywp
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

Re: if statement or if satement

Posted: 18 Dec 2023 18:46
by Squashman
When you read the help file for the IF command where did it show usage for using a PIPE or OR?

Re: if statement or if satement

Posted: 18 Dec 2023 19:16
by Aacini
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

Re: if statement or if satement

Posted: 18 Dec 2023 19:55
by Batcher

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
    )
)

Re: if statement or if satement

Posted: 19 Dec 2023 10:41
by goodywp
Thanks Batcher!
It is great!