Click here to Skip to main content
12,504,002 members (59,142 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Windows batch
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 6-Nov-12 11:22am
G4mm4R4y1.1K
Comments
   
Why? do you mean arithmetic subtraction, or what?
--SA
Jaydman2102 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
Jaydman2102 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Probably, I'm guessing at the problem but I assume "it doesn't work".
Try this
@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
  Permalink  
Comments
Sergey Alexandrovich Kryukov 12-Nov-12 22:55pm
   
My 5. The key here is '/a' in 'set', arithmetic operation...
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100