Page 1 of 1
[Question] Check if a variable is between numbers
Posted: 11 Nov 2011 14:44
by Ranguna173
Hello!
My question is if it is possible to see if a variable is between two numbers. Ex:.
I have a variable called Num1 and it contains a random number.
Now I want to now if that number is between 1 and 5.
How do I do that?
Pleas help and thanks!
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:02
by dbenham
Code: Select all
if %Num1% geq 1 if Num1 leq 5 echo %Num1% is between 1 and 5
This is pretty basic stuff. Read up on IF (HELP IF)
Dave Benham
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:02
by Ed Dyreen
'
Code: Select all
@echo off
set $var=hello &call :§scope
set $var=10 &call :§scope
set $var=3 &call :§scope
pause
exit /b 0
:§scope ()
::(
if defined $var (
if %$var% equ +%$var% (
if %$var% lss 5 (
if %$var% gtr 0 (
echo.variable matches scope.
)
)
)
)
::)
exit /b 0
a macro would be easier but that may be too complex...
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:09
by dbenham
Should read either
if %$var% lss 6 (or
if %$var% leq 5 (Ed Dyreen wrote:a macro would be easier but that may be too complex...

classic
Dave Benham
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:14
by Ranguna173
The creation of this topic is my ignorance.
When I was reading the "if /?" i skipped the "gtr" "lss" "equ"..etc. section..
I'm sorry!
And thanks for your help.
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:18
by Ranguna173
Ed Dyreen wrote:'
]a macro would be easier but that may be too complex...
dbenham wrote:Ed Dyreen wrote:[code]
Ed Dyreen wrote:a macro would be easier but that may be too complex...

classic
Dave Benham
Wait.. Are you making fun of me?
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:23
by dbenham
No - I was not making fun of you.
I found Ed's statement to be humorous; it is an oxymoron - meaning a statement that contradicts itself.
Dave Benham
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 15:39
by Ranguna173
dbenham wrote:it is an oxymoron - meaning a statement that contradicts itself.
Dave Benham
Oh.. I get it.
Maybe the "easy" ment something else or Ed thought that it would be easy for him but to complex
for me.. (In which he is wrong

)
Re: [Question] Check if a variable is between numbers
Posted: 11 Nov 2011 16:27
by Ed Dyreen
'
I mean macro's are only beneficial if you are going to depend on them multiple times during execution. Otherwise it's a waste of developing time.