3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Advanced Batch

Step 4SET Command - User Input (3/4)

SET Command - User Input (3/4)
«
  • cmd set udefine.JPG
  • cmd missing operand set error.JPG
  • cmd set udefine cannot evaulate.JPG
  • notepad Calculator.JPG
  • cmd calculator.JPG
The SET also has the ability to prompt the user for input.

By adding /p to the SET parameters, it transforms it from a normal variable setter to a user-controlled variable setter.

SET /p UDefine=

With the /p, the program actually pauses, and waits for the User's input.

But wait, I don't see a /a parameter, does that mean that the variable is a string only?

Well, sort of. The /p of the parameters completely negates the /a, and if you attempt it, you simply get a Missing operand error. This means that the User Defined variable will not be able to evaluate expressions.

So what can one do?

Well, here's a tricky trick that I thought of that we can use.
The SET Command does not all the simultaneous use of parameters /p and /a, correct? Well, what about the sequential use of the parameters /a and /p?
Ahhh... you sly boots.

@ECHO OFFECHO Calculator Version 1.0ECHO.SET /p UDefine=SET /a UDefine=%UDefine%ECHO =ECHO %UDefine%ECHO.PAUSE

Nice calculator ya got there. If you haven't figured it out by now, the {{{ECHO.}}} is a blank line.

Isn't that cool-cool?
« Previous StepDownload PDFView All StepsNext Step »
12 comments
Aug 17, 2010. 7:41 AMFiles says:
I mine as well should add my variation.I got ideas from various people, but I mainly just edited and added in some new echo's and added some extra info.



@ECHO OFF
title Command Prompt - Made by NetworkNinja Editted by Mikeyy
color 20
echo Calculator V1.3
echo Made by NetworkNinja echo Editted by Mikeyy
echo ---------------------
echo LEARN:
echo * = Multiply
echo / = Divide
echo + = Addition
echo - = Subtracting
echo ---------------------
:blah
ECHO.
SET /p UDefine=
SET /a UDefine=
%UDefine%
ECHO =
ECHO
%UDefine%
ECHO.
PAUSE
ECHO.
echo THANK YOU FOR USING OUR CALCULATOR!
ECHO -------------------------------------------------------------------------------- ECHO.
goto blah
May 18, 2008. 8:36 AMelmynase says:
can you divide?
Apr 16, 2009. 6:00 PMNetworkNinja says:
yes, / is divide
ex. 9/3=3
Jul 17, 2009. 1:21 AMDNR says:
how to solve decimal values
Apr 10, 2010. 8:50 PMGuard13007 says:
 Batch files mess up over decimals, blame Microsoft.
Jul 18, 2009. 1:48 PMelmynase says:
good question !!
Apr 10, 2010. 8:50 PMGuard13007 says:
 Batch files mess up over decimals, blame Microsoft.
Apr 16, 2009. 6:00 PMNetworkNinja says:
This is mine, has black letters on green background. Looks kool.

@ECHO OFF
color 20
:blah
ECHO Calculator Version 1.0
ECHO.
SET /p UDefine=
SET /a UDefine=%UDefine%
ECHO =
ECHO %UDefine%
ECHO.
PAUSE
goto blah
Jul 18, 2009. 11:54 PMDNR says:
how to solve decimal values
Apr 10, 2010. 8:49 PMGuard13007 says:
 Batch files don't like decimals, and screw up over them for some reason. Blame Microsoft.
Apr 16, 2009. 7:45 PMNetworkNinja says:
My newer version (it just looks better)

@ECHO OFF
color 20
:blah
ECHO Calculator Version 1.1
ECHO.
SET /p UDefine=
SET /a UDefine=%UDefine%
ECHO =
ECHO %UDefine%
ECHO.
PAUSE
ECHO.
ECHO --------------------------------------------------------------------------------
ECHO.
goto blah

On the v1.0 Neo gave us, there was no loop so you'd have to re-open the batch, and if you insert a "goto" command, there was no gap btwn the title and last line before it looped. I fixed those things.
Feb 10, 2010. 8:36 AMgraboy says:
Im not clear, what exactly does the /a  thing do?
Apr 10, 2010. 8:37 PMGuard13007 says:
 It's for having expressions. If you put "set variable=3-9" it will simply make the variable equal 3-9. If you put "set /a variable=3-9" it will make the variable equal -6 (the answer to 3-9). Get it? Got it. Good.
Feb 12, 2010. 10:20 AMsuperbursihido says:
my comment goes lalalallalaalallalal lala
Jan 21, 2008. 5:47 AMlewis36 says:
my calculator exits after i do 1 equation, what can i change to make it not shutdown
Feb 4, 2008. 6:07 PMGrimesFace says:
Yeah, I just put a loop in mine. Its shorter than simking's, but I like it better that way.

@echo off
echo Calculator Version 1.0
echo.
:top
Set /p UDefine=
Set /a UDefine=%UDefine%
Echo =
echo %udefine%
echo.
goto top
pause

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
22
Followers
5
Author:Neodudeman