if condition on integer

G

Gustavio

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
 
W

William Allen

Gustavio said:
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
 
T

Timo Salmi

Gustavio said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top