Computing.Net > Forums > Disk Operating System > can dos batch files do math operations?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

can dos batch files do math operations?

Reply to Message Icon

Name: David
Date: December 28, 2000 at 09:24:12 Pacific
Comment:

can dos batch files do math operations



Sponsored Link
Ads by Google

Response Number 1
Name: ¤¤¥¤Ö
Date: December 28, 2000 at 13:14:32 Pacific
Reply:

If the question is to win a bet on trivia, then I'd say yes.
(There was a young man from Racine, who invented a screwing machine. Concave or convex, it would take either sex, but oh what a b---tard to clean!)
In other words, it sure isn't easy.
For example, one way to do so would be:
to add two single digit number that are entered on the command line,
if %1==1 goto 1x
if %1==2 goto 2x
if %1==3 goto 3x
if %1==4 goto 4x
if %1==5 goto 5x
if %1==6 goto 6x
if %1==7 goto 7x
if %1==8 goto 8x
if %1==9 goto 9x
if %1==0 goto zerox
goto end
:1x
if %2==1 goto say2
if %2==2 goto say3
if $2==3 goto say4
----dot dot dot---
:say4
echo 4
goto done
:say5
echo 5
goto done
---dot dot dot---
Using multiple batch files, and loops, this
process could be made even easier.
For example, you could write a small file that will increment (or decrement) an environment variable, like:
if %myvar%==1 goto l2
if %myvar%--2 goto l3
---dot dot dot---
:l2
set myvar=2
goto done
---etc.


0

Response Number 2
Name: Laurence
Date: December 28, 2000 at 13:20:12 Pacific
Reply:

Absolutely! But, not as fast as a dedicated
executable. I have on that adds, subtracts,
multiplies and divides whole positive integers, but I used the "bang" principle so
it is only practical for very small numbers.
I plan on writing a much faster algorithm when I get time.
http://home7.inet.tele.dk/batfiles/monthly/jun2000.htm

Also check out:
http://home7.inet.tele.dk/batfiles/main/showcase.htm#savage

http://home7.inet.tele.dk/batfiles/main/showcase.htm#lavedas

http://home7.inet.tele.dk/batfiles/main/showcase.htm#fairhead




Batfiles: The DOS batch file programming handbook




0

Response Number 3
Name: bubbletrap
Date: December 28, 2000 at 19:18:25 Pacific
Reply:

Here's a sample that I use to automatically run scandisk every tenth boot (by calling from autoexec.bat):
@echo off
call c:\batch\setcount.bat
if not %count%==0 goto 1
set count=1
goto end
:1
if not %count%==1 goto 2
set count=2
goto end
:2
if not %count%==2 goto 3
set count=3
goto end
:3
if not %count%==3 goto 4
set count=4
goto end
:4
if not %count%==4 goto 5
set count=5
goto end
:5
if not %count%==5 goto 6
set count=6
goto end
:6
if not %count%==6 goto 7
set count=7
goto end
:7
if not %count%==7 goto 8
set count=8
goto end
:8
if not %count%==8 goto 9
set count=9
goto end
:9
if not %count%==9 goto 0
scandisk
set count=0
:end
echo @set count=%count%>c:\batch\setcount.bat


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: can dos batch files do math operations?

Can a batch file count directories? www.computing.net/answers/dos/can-a-batch-file-count-directories/7410.html

File Size in DOS Batch file www.computing.net/answers/dos/file-size-in-dos-batch-file/3105.html

Dos batch file. www.computing.net/answers/dos/dos-batch-file/9090.html