Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 6-Nov-12 11:22am
G4mm4R4y1.1K
Comments
Sergey Alexandrovich Kryukov at 6-Nov-12 17:43pm
   
Why? do you mean arithmetic subtraction, or what?
--SA
Jaydman2102 at 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 at 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 at 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 at 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 at 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
0 CPallini 365
1 OriginalGriff 275
2 Sergey Alexandrovich Kryukov 247
3 George Jonsson 130
4 ChauhanAjay 104
0 OriginalGriff 6,464
1 Sergey Alexandrovich Kryukov 5,915
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
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