View Full Version : if condition on integer


Gustavio
08-30-2005, 05:30 AM
Hello,

I would like to know how to make the condition for an "if" allowing %%i to
be an integer only or go to exit.

Thanks in advance.
Cheers

William Allen
08-30-2005, 08:18 AM
"Gustavio" <lala@lala.com> wrote in message
> Hello,
>
> I would like to know how to make the condition for an "if" allowing %%i to
> be an integer only or go to exit.

Try testing the VariableContents for equality with +VariableContents,
this test is treated as True if the VariableContents are a numeric integer.

This demo shows the syntax, and uses ECHO commands for
illustration (you could replace them with GOTO commands to
to route flow to :EOF). The FOR statement tests four sample
tokens to report which are integers:

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
FOR /f "tokens=1-4" %%A IN ("1.5 2x text 1001") DO (
IF %%A EQU +%%A ECHO %%A is a integer
IF %%B EQU +%%B ECHO %%B is a integer
IF %%C EQU +%%C ECHO %%C is a integer
IF %%D EQU +%%D ECHO %%D is a integer
)

====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

Screen capture shows operation:

============Screen capture Windows 2000 simulated in Win95
C:\WORK>demo
1001 is a integer

C:\WORK>
============End screen capture

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/

Timo Salmi
08-30-2005, 08:39 PM
Gustavio wrote:
> I would like to know how to make the condition for an "if"
> allowing %%i to be an integer only or go to exit.

106} How to test whether a variable is a non-negative integer?
130306 Jul 12 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Jerold Schulman
09-07-2005, 06:16 PM
On Tue, 30 Aug 2005 13:30:33 +0900, "Gustavio" <lala@lala.com> wrote:

>Hello,
>
>I would like to know how to make the condition for an "if" allowing %%i to
>be an integer only or go to exit.
>
>Thanks in advance.
>Cheers
>
See tip 9692 » How can a batch script determine if a variable or parameter is an integer?
in the 'Tips & Tricks' at http://www.jsifaq.com


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com