DosTips.com

A Forum all about DOS Batch
It is currently 29 Jun 2016 04:49

All times are UTC-06:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 12 Sep 2011 22:13 
Offline

Joined: 01 Sep 2011 03:54
Posts: 147
Location: Perth, Western Australia
Hi,
Could someone give me a simple sintax overview to the various arguments involving "gtr" "lss" etc in the "if" command.

Any help would be greatly appreciated,
Rileyh


Top
   
PostPosted: 13 Sep 2011 16:54 
Offline

Joined: 07 Sep 2011 18:32
Posts: 20
Location: Eastern Australia
have you looked at IF /? :?:


Top
   
PostPosted: 13 Sep 2011 20:44 
Offline

Joined: 01 Sep 2011 03:54
Posts: 147
Location: Perth, Western Australia
@bob d
Yes I have looked at that and it is quite hard to understand.
Also it is very brief and has not much info on it

Rileyh


Top
   
PostPosted: 14 Sep 2011 02:43 
Offline

Joined: 01 Jul 2011 08:47
Posts: 143
See the code and test with different numbers to understand this:
Code:
@echo off
cls
echo.
echo  Overview of the various comparison operations in the command IF
echo.
set /p val1= value 1:
set /p val2= value 2:
echo.
echo   IF %val1% EQU %val2% (command if TRUE) ELSE command if FALSE
IF %val1% EQU %val2% (ECHO     TRUE) ELSE ECHO     FALSE
echo.
echo   IF %val1% NEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% NEQ %val2% (ECHO     TRUE) ELSE ECHO     FALSE
echo.
echo   IF %val1% LSS %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LSS %val2% (ECHO     TRUE) ELSE ECHO     FALSE
echo.
echo   IF %val1% LEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LEQ %val2% (ECHO     TRUE) ELSE ECHO     FALSE
echo.
echo   IF %val1% GTR %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GTR %val2% (ECHO     TRUE) ELSE ECHO     FALSE
echo.
echo   IF %val1% GEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GEQ %val2% (ECHO     TRUE) ELSE ECHO     FALSE

If you want use the value as string use the quotation marks.

IF "%val1%" LSS "%val2%" ECHO The first word is alphabetically before the second word.
IF /I "%val1%" EQU "%val2%" ECHO Lowercase and uppercase are ignored - ABC is the same as abc

Robert


Top
   
PostPosted: 14 Sep 2011 02:57 
Offline

Joined: 01 Sep 2011 12:52
Posts: 34
BASIC:

Code:
line1: if VARIABLE1 gtr VARIABLE2 goto 1greaterthan2
line2: if VARIABLE1 lss VARIABLE2 goto 1lessthan2
line3: if VARIABLE1 equ VARIABLE2 goto 1equal2
line4: if VARIABLE1 neq VARIABLE2 goto 1notequal2
line5: if VARIABLE1 leq VARIABLE2 goto 1lessorequal2
line6: if VARIABLE1 geq VARIABLE2 goto 1greaterorequal2


Explaination:

line1: if the first variable (VARIABLE1) is greater than the second (VARIABLE2) then skip to 1greaterthan2

line2: if the first variable (VARIABLE1) is less the second (VARIABLE2) then skip to 1lessthan2

line3: if the first variable (VARIABLE1) is equal the second (VARIABLE2) then skip to 1equal2

line4: if the first variable (VARIABLE1) is not equal the second (VARIABLE2) then skip to 1notequal2

line5: if the first variable (VARIABLE1) is less or equal the second (VARIABLE2) then skip to 1lessorequal2

line6: if the first variable (VARIABLE1) is greater or equal the second (VARIABLE2) then skip to 1greaterorequal2


Hope this helped!
-Exouxas


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited