China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-30 02:22
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Question] How to check numeric values under DOS View 726 Replies 3
Original Poster Posted 2006-03-22 10:10 ·  中国 广西 贺州 电信
初级用户
Credits 58
Posts 17
Joined 2006-03-22 10:05
20-year member
UID 52567
Status Offline
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?
Floor 2 Posted 2006-03-22 14:49 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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.................
Floor 3 Posted 2006-03-22 15:17 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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%
Floor 4 Posted 2006-03-22 18:02 ·  中国 广西 来宾 电信
初级用户
Credits 58
Posts 17
Joined 2006-03-22 10:05
20-year member
UID 52567
Status Offline
Hehe, quite interesting. Thanks.
Forum Jump: