Instructables

Some Cool Batch Applications

Step 1: Batch Calculator

Picture of Batch Calculator
This is...well... a calculator.
just copy and paste into NOTEPAD and save as calculator.bat
the filename is not important but the extension MUST be saved as " .bat "

@echo off
title Batch Calculator by seJma
color 1f
:top
echo --------------------------------------------------------------
echo Welcome to Batch Calculator by seJma
echo --------------------------------------------------------------
echo.
set /p sum=
set /a ans=%sum%
echo.
echo = %ans%
echo --------------------------------------------------------------
pause
cls
echo Previous Answer: %ans%
goto top
pause
exit
 
Remove these adsRemove these ads by Signing Up
marmig04047 months ago
I like your version but i have made my own.
anyone can check it out if they want but please give credit when sharing. Thank you!

@echo off
title Calculator
color 0a
echo Welcome to The Basic Arithmetic Calculator
echo Made By Martin Miglio
ping localhost -n 3 >nul

:LOADING
cls
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
ping localhost -n 2 >nul
cls
echo Loading....
ping localhost -n 2 >nul
cls
echo Loading.....
ping localhost -n 2 >nul
ping localhost -n 2 >nul
color 0a

:START
cls
echo What Type of Math would you like to do?
echo Add, Subtract, Multiply, or Divide.
set /p math=
IF '%math%' == 'Add' GOTO ADD
IF '%math%' == 'add' GOTO ADD
IF '%math%' == 'Subtract' GOTO SUB
IF '%math%' == 'subtract' GOTO SUB
IF '%math%' == 'Multiply' GOTO MULTIPLY
IF '%math%' == 'multiply' GOTO MULTIPLY
IF '%math%' == 'Divide' GOTO DIVIDE
IF '%math%' == 'divide' GOTO DIVIDE
Exit

:ADD
Cls
GOTO NUMBERSADD
pause
exit

:SUB
Cls
GOTO NUMBERSSUB
pause
exit

:MULTIPLY
Cls
GOTO NUMBERSMULTIPLY
pause
exit

:DIVIDE
Cls
GOTO NUMBERSDIVIDE
pause
exit

:NUMBERSADD
echo What is the First Number you would like to Add?
set /p number1=
cls
echo What is the Second Number you would like to Add?
set /p number2=
cls

GOTO ADD2
exit

:NUMBERSSUB
echo What is the First Number you would like to Subtract?
set /p number1=
cls
echo What is the Second Number you would like to Subtract?
set /p number2=
cls
GOTO SUB2
exit

:NUMBERSMULTIPLY
echo What is the First Number you would like to Multiply?
set /p number1=
cls
echo What is the Second Number you would like to Multiply?
set /p number2=
cls
GOTO MULTIPLY2
exit

:NUMBERSDIVIDE
echo What is the First Number you would like to Divide?
set /p number1=
cls
echo What is the Second Number you would like to Divide?
set /p number2=
cls
GOTO DIVIDE2
exit

:ADD2
Set /A result = %number1% + %number2%
echo The answer is %result%.
Pause
GOTO START
exit

:SUB2
Set /A result = %number1% - %number2%
echo The answer is %result%.
pause
GOTO START
exit

:MULTIPLY2
Set /A result = %number1% * %number2%
echo The answer is %result%.
pause
GOTO START
exit

:DIVIDE2
Set /A result = %number1% / %number2%
echo The answer is %result%.
pause
GOTO START
exit




fin
Joe Diffie11 months ago
That's pretty cool stuff!
I'm working on a forum where I need to do just 2 simple math problems.

Var/.4 =x and var/.6=x

I don't know what the rise in the number by .4 and .6 actually really does for the company but that's the way they want it.

does anyone know how to build an easy app for that.
just 3 text boxes. one for entering an amount and an enter button that does the math and enters that data in the .4 and .6 math answers text boxes simultaneously.
They don't even need to be labeled.
account3r24 years ago
@echo off title Batch Calculator by account3r2 color 1f :top echo -------------------------------------------------------------- echo Welcome to Batch Calculator by account3r2 echo -------------------------------------------------------------- echo. set /p sum= set /a ans=%random% echo. echo = %ans% echo -------------------------------------------------------------- pause cls echo Previous Answer: %ans% goto top pause exit
Laserman5954 years ago
here is a really simple version of the batch calculator

@echo off
title batch calculator v 2.0
color 0e
:top
echo  --------------------------------------------------------------
echo welcome to the batch calculator v 2.0
echo type your math problem bellow
echo  --------------------------------------------------------------
set /p equation=
set /a ans= %equation%
cls
echo %ans%
pause > Nul
cls
echo last answer %ans%
goto top
exit
higginsiv5 years ago
@leeabc123 hey, thanks for the comments on my tic tac toe, and good luck w/ yours. i recently added a single player tic tac toe, u can download it from higginsbatch.webs.com if you want. i also have my other batch files there for anybody to see. u can see the source from the downloads too. tell me what you think!
Heres another version of the calculator:

@echo off
color 0A
title CALCULATOR VERSION 1.2
:loop
cls
echo by BMR
echo _
echo by skylord55816
echo.
echo Calculator Version 1.2
echo -----------------------------------------------
echo * = MULTIPLY
echo + = ADD
echo - = SUBTRACT
echo 2 = SQUARED
echo / = DIVIDE
echo After an equation, type CLEAR to clear the screen of your equations, type KEEP to leave them there, or

type EXIT to leave.
:noclear
set /p UDefine=
set /a UDefine=%UDefine%
echo.
echo =
echo.
echo %UDefine%
echo KEEP, CLEAR, OR EXIT?
set /p clearexitkeep=
if %clearexitkeep%==CLEAR goto loop
if %clearexitkeep%==KEEP echo. && goto noclear
if %clearexitkeep%==EXIT (exit)
:misspell
echo.
echo -----------------------------------------------
echo You misspelled your command. Please try again (make sure you are typing in all caps LIKE THIS).
echo Commands:
echo CLEAR Clear all previous equations and continue calculating.
echo KEEP Keep all previous equations and continue calculating.
echo EXIT Leave your calculating session
echo Enter in a command now.
set /p clearexitkeep=
if %clearexitkeep%==CLEAR goto loop
if %clearexitkeep%==EXIT (exit)
if %clearexitkeep%==KEEP goto noclear
goto misspell

Hope you like it!!!
There are supposed to be two carots (a carot is Shift+6) in front of the 2 after squared... Command prompt leaves the first one out for some reason so you have to have two... And if you have 2, then Instructables thinks you are trying to draw something innapropriate.
leeabc1235 years ago
Ok, I just re-read your comment above... (higginsiv says:Jan 29, 2009. 7:09 PM) It is way easier than what I am trying to do!! I haven't actually had time recently as I have been busy at work with.... well work!!! But hopefully tomorrow I can launch into it again and try get somewhere. Lately I struggle sleeping because I dream up code for things! Anyway, I am off to bed... good night
leeabc1235 years ago
Hi there. When did you post this code? I have an interesting game for you to try and write! I was trying to write OXO (Tic Tac Toe) and it proved to be too difficult. Maybe I was going about it the wrong way using 'for /f' loops... Any ideas? Cheers - I really enjoy your calculator... so simple yet so hard. Where did you learn your programming?
Sejma (author)  leeabc1235 years ago
hmmm...i haven't programmed in Batch for quite while, Tic Tac Toe is a clever idea though. I'll give it a shot when I have some free time. Let me know if you get a breakthrough. I'm busy taking a Java development course at the moment, so my Batch is quite rusty. I learned batch, mainly from Instructables and just looking at examples. Thanks for the positive feedback - sejma
leeabc123 Sejma5 years ago
(In response to the OXO code...)

Hi, I looked at the code on you tube.... and it was a much simpler version of the one I did!! I eventualy got one working but it doesnt score yet... it looks like this:
example:
X:O:X
O:X:O
O:O:X

That is just an example of the layout!
As soon as I crack the score I will post it up! It is pretty good, but your score system is fantastic!

I used loads of for /f loops with setlocal enabledelayedexpansion.
But I am going to make my script alot simpler by using your 'place selcetion' by number method. (I currently use set /p row= and set /p colum= which as you can guess makes the game a lot longer and boring!)

Watch this space! - it will take ages so watch this space, but dont hold your breathe! Keep up the good work guys