中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-18 00:21
47,814 topics / 349,907 posts / today 4 new / 48,259 members
DOS疑难解答 & 问题讨论 (解答室) » [Question] How to check numeric values under DOS
Printable Version  783 / 3
Floor1 MIN Posted 2006-03-22 10:10
初级用户 Posts 17 Credits 58
For example, how do I check whether the value entered by the user is a valid expression?
For an IP address, how do I check whether it is less than 255?
Floor2 bagpipe Posted 2006-03-22 14:49
银牌会员 Posts 425 Credits 1,144 From 北京
You can set up a pattern like 192.168.0.XX, where XX represents a variable. You can define this when writing the batch file, and then use the IF statement to check it.
EQU - equal to
NEQ - not equal to
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to
Use these values to check the range of your number. The error-handling ability of batch files isn't very strong to begin with, so it depends on how you write it and how well you can make the error handling.................
Floor3 bagpipe Posted 2006-03-22 15:17
银牌会员 Posts 425 Credits 1,144 From 北京
Better to give an example

@echo off
:start
set /p oo=Enter your numeric:
if %oo% LSS 0 goto ooo
if %oo% GEQ 255 goto ooo
goto ii
oo
echo Sorry! The number you entered is incorrect!!!
goto :start
:ii
echo The IP address you set is :192.168.0.%oo%
Floor4 MIN Posted 2006-03-22 18:02
初级用户 Posts 17 Credits 58
Hehe, quite interesting. Thanks.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023