Step 4SET Command - User Input (3/4)
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 Step | Download PDFView All Steps | Next Step » |



















































@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
ex. 9/3=3
@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
@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.
@echo off
echo Calculator Version 1.0
echo.
:top
Set /p UDefine=
Set /a UDefine=%UDefine%
Echo =
echo %udefine%
echo.
goto top
pause