I've compiled an interesting batch script for NT-based systems like 2K/XP, which can calculate simple expressions. It's just an entry-level one, so I'm posting it here.
The latest version of this batch script can be downloaded from the "DIY" directory on my E drive.
[ Last edited by namejm on 2007-2-3 at 09:49 PM ]
@echo off
echo Welcome to use the 2K/XP expression calculation batch script
echo Made by Brglng 2005.8.15
echo Download address: http://brglng.ys168.com
echo Please report bugs in time! Email:sky-0310@sohu.com
echo.
echo Note: This batch script can only be used in NT-based systems, not in Win9x/Me/DOS!
echo If using in the command line, please use "Command Prompt" in the accessories or use cmd.exe, not command.com!
echo This batch file can only be used in Chinese version of
echo Windows 2K/XP/2003...!
echo Do not use command.com instead of cmd.exe!
pause
:inputExpr
set Expr=
set EvalExpr=
echo.
echo Please enter the expression (enter "?" to view help):
set /p Expr=
if "%Expr%"=="" (
goto inputExpr
)
if "%Expr%"=="?" (
echo This expression calculation batch script is very simple and supports the following operations in decreasing order of priority:
echo ^(^) ^- Grouping
echo ^! ^~ ^- ^- Unary operators
echo ^* ^/ ^% ^- Arithmetic operators
echo ^+ ^- ^- Arithmetic operators
echo ^<^< ^>^> ^- Logical shift
echo ^- Bitwise "AND"
echo ^^ ^- Bitwise "XOR"
echo ^| ^- Bitwise "OR"
echo ^= ^*^= ^/^= ^%^= ^+^= ^-^= ^- Assignment
echo ^&^= ^^^= ^|^= ^<^<^= ^>^>^=
echo ^, ^- Expression separator
echo If you use any logical or remainder operators, you need to enclose the expression string in quotes. Any non-numeric string key in the expression is taken as an environment variable name, and the values of these environment variable names are converted to numbers before use. If an environment variable name is specified but not defined in the current environment, the value will be set to zero. This allows you to use environment variable values for calculations without typing those % symbols to get their values. Except for hexadecimal numbers with 0x prefix and octal numbers with 0 prefix, numeric values are decimal numbers. Therefore, 0x12 is the same as 18 and 022. Please note that octal formulas can be easily confused: 08 and 09 are invalid numbers because 8 and 9 are not valid octal digits.
goto inputExpr
)
set /a EvalExpr="%Expr%"
if "%EvalExpr%"=="" (
echo Input error!
goto inputExpr
)
echo The calculation result is: %EvalExpr%
:if_save
set SaveEval=
echo.
echo Do you want to save the expression and calculation result to a file ?
set /p SaveEval=
if "%SaveEval%"=="Y" goto save
if "%SaveEval%"=="y" goto save
if "%SaveEval%"=="N" goto next
if "%SaveEval%"=="n" goto next
goto if_save
:save
echo Please enter the file path and file name (such as C:\Windows\file.txt. If no path is entered, it means the current folder, leaving it blank means the last entered path):
set /p SaveEvalPath=
echo %Expr%=%EvalExpr% >>%SaveEvalPath%
echo The expression and calculation result have been saved to %SaveEvalPath%!
:next
set EvalNext=
echo 1. Continue calculation 2. Exit
set /p EvalNext=
if "%EvalNext%"=="1" goto inputExpr
if "%EvalNext%"=="2" goto end
goto next
:end
echo Thank you for using! Press any key to exit...
pause >nul
set Expr=
set EvalExpr=
set SaveEval=
set SaveEvalPath=
set EvalNext=
The latest version of this batch script can be downloaded from the "DIY" directory on my E drive.
[ Last edited by namejm on 2007-2-3 at 09:49 PM ]
32位才是DOS未来的希望
个人网志:http://sololand.moe
个人网志:http://sololand.moe

DigestI