Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need help with subtracting or adding with variables kind of like this
@echo off
set var=5
echo %var%
pause
echo ___________________________________________
set /a %var% +1
echo %var%
Pause
Can you help me?
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-12 17:43pm    
Why? do you mean arithmetic subtraction, or what?
--SA
G4mm4R4y 12-Nov-12 22:51pm    
Well it solved but yes arithmetic I'm almost finished with my RPG that I needed this for but i have another question open holding another problem. Please help me with it if you can.
Sergey Alexandrovich Kryukov 12-Nov-12 23:00pm    
Well, I will, if I can. Where is that question?
In the meanwhile, I provided a reference to a very useful batch which you can use to learn batch programming or get reference information. Please see my answer; hope it will help you.
--SA
G4mm4R4y 12-Nov-12 23:16pm    
Here is the article i posted and ill check out that website. Thanks!
http://www.codeproject.com/Questions/492898/Windowsplusbatchplusclosesplusonpluswrongplusvaria
Sergey Alexandrovich Kryukov 12-Nov-12 23:42pm    
I already answered, please see.
--SA

Probably, I'm guessing at the problem but I assume "it doesn't work".
Try this
CSS
@echo off

echo Testing Set /P and Set /A
set /p NUM1=Enter a number :
set /p NUM2=Enter another number :

set /a RESULT=NUM1+NUM2
echo %NUM1% + %NUM2% = %RESULT%

REM your stuff corrected
set var=5
echo %var%
set /a var=var+1
echo %var%

pause
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Nov-12 22:55pm    
My 5. The key here is '/a' in 'set', arithmetic operation...
--SA
In addition to a correct answer by Alan N:

This wonderful batch script by Rob van der Woude, http://www.robvanderwoude.com[^], with improvements by Johan Parlevliet build a complete help on all batch commands on your system:
http://www.robvanderwoude.com/allhelp.php[^],
http://www.robvanderwoude.com/files/allhelp_nt.txt[^].

Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900