[Question] Check if a variable is between numbers
Moderator: DosItHelp
-
- Posts: 104
- Joined: 28 Jul 2011 17:32
[Question] Check if a variable is between numbers
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!
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
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
'
a macro would be easier but that may be too complex...
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
Re: [Question] Check if a variable is between numbers
Should read either if %$var% lss 6 (Ed Dyreen wrote:Code: Select all
...
if %$var% lss 5 (
...
or if %$var% leq 5 (
Ed Dyreen wrote:a macro would be easier but that may be too complex...




Dave Benham
-
- Posts: 104
- Joined: 28 Jul 2011 17:32
Re: [Question] Check if a variable is between numbers
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.
When I was reading the "if /?" i skipped the "gtr" "lss" "equ"..etc. section..
I'm sorry!
And thanks for your help.
-
- Posts: 104
- Joined: 28 Jul 2011 17:32
Re: [Question] Check if a variable is between numbers
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
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
I found Ed's statement to be humorous; it is an oxymoron - meaning a statement that contradicts itself.
Dave Benham
-
- Posts: 104
- Joined: 28 Jul 2011 17:32
Re: [Question] Check if a variable is between numbers
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
'
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.
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.