How to reduce value of variable in batch?












-1















I need to reduce value of variable by 3 but it says Missing operand



:(1-3)
set /p speed=">> "
if %speed% geq 4 goto duzo
if %speed% leq 0 goto malo
set x=4
set /a x==%x%-%speed%


I tried that too:



set /a speed==4-%speed%


Edit:



Now I have a problem with



choice


comand. I'm using windows 10. When I'm adding for example



echo Do you want to try again? 
choice /t 10 /c yn /d n


program stops as it comes and I cannot do anything to it










share|improve this question




















  • 1





    Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

    – Squashman
    Jan 2 at 17:46











  • There's no problem with your choice command, and tested on win10 it's okay.

    – Tiw
    Jan 4 at 3:22











  • Okay now it's working

    – maxmarsz
    Jan 4 at 5:30











  • I think you need to use big letters in arguments

    – maxmarsz
    Jan 4 at 5:31











  • @maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

    – Tiw
    Jan 5 at 3:30
















-1















I need to reduce value of variable by 3 but it says Missing operand



:(1-3)
set /p speed=">> "
if %speed% geq 4 goto duzo
if %speed% leq 0 goto malo
set x=4
set /a x==%x%-%speed%


I tried that too:



set /a speed==4-%speed%


Edit:



Now I have a problem with



choice


comand. I'm using windows 10. When I'm adding for example



echo Do you want to try again? 
choice /t 10 /c yn /d n


program stops as it comes and I cannot do anything to it










share|improve this question




















  • 1





    Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

    – Squashman
    Jan 2 at 17:46











  • There's no problem with your choice command, and tested on win10 it's okay.

    – Tiw
    Jan 4 at 3:22











  • Okay now it's working

    – maxmarsz
    Jan 4 at 5:30











  • I think you need to use big letters in arguments

    – maxmarsz
    Jan 4 at 5:31











  • @maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

    – Tiw
    Jan 5 at 3:30














-1












-1








-1








I need to reduce value of variable by 3 but it says Missing operand



:(1-3)
set /p speed=">> "
if %speed% geq 4 goto duzo
if %speed% leq 0 goto malo
set x=4
set /a x==%x%-%speed%


I tried that too:



set /a speed==4-%speed%


Edit:



Now I have a problem with



choice


comand. I'm using windows 10. When I'm adding for example



echo Do you want to try again? 
choice /t 10 /c yn /d n


program stops as it comes and I cannot do anything to it










share|improve this question
















I need to reduce value of variable by 3 but it says Missing operand



:(1-3)
set /p speed=">> "
if %speed% geq 4 goto duzo
if %speed% leq 0 goto malo
set x=4
set /a x==%x%-%speed%


I tried that too:



set /a speed==4-%speed%


Edit:



Now I have a problem with



choice


comand. I'm using windows 10. When I'm adding for example



echo Do you want to try again? 
choice /t 10 /c yn /d n


program stops as it comes and I cannot do anything to it







batch-file windows-10






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 6:52







maxmarsz

















asked Jan 2 at 16:47









maxmarszmaxmarsz

285




285








  • 1





    Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

    – Squashman
    Jan 2 at 17:46











  • There's no problem with your choice command, and tested on win10 it's okay.

    – Tiw
    Jan 4 at 3:22











  • Okay now it's working

    – maxmarsz
    Jan 4 at 5:30











  • I think you need to use big letters in arguments

    – maxmarsz
    Jan 4 at 5:31











  • @maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

    – Tiw
    Jan 5 at 3:30














  • 1





    Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

    – Squashman
    Jan 2 at 17:46











  • There's no problem with your choice command, and tested on win10 it's okay.

    – Tiw
    Jan 4 at 3:22











  • Okay now it's working

    – maxmarsz
    Jan 4 at 5:30











  • I think you need to use big letters in arguments

    – maxmarsz
    Jan 4 at 5:31











  • @maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

    – Tiw
    Jan 5 at 3:30








1




1





Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

– Squashman
Jan 2 at 17:46





Nowhere in the help file for the SET command does it say that a double equals is a valid operator. Where did you find this example on the Internet? You can simplify the assignment like this: set /a speed-=4.

– Squashman
Jan 2 at 17:46













There's no problem with your choice command, and tested on win10 it's okay.

– Tiw
Jan 4 at 3:22





There's no problem with your choice command, and tested on win10 it's okay.

– Tiw
Jan 4 at 3:22













Okay now it's working

– maxmarsz
Jan 4 at 5:30





Okay now it's working

– maxmarsz
Jan 4 at 5:30













I think you need to use big letters in arguments

– maxmarsz
Jan 4 at 5:31





I think you need to use big letters in arguments

– maxmarsz
Jan 4 at 5:31













@maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

– Tiw
Jan 5 at 3:30





@maxmarsz What did you do to make it working? I just copied your lower case command and it worked fine.

– Tiw
Jan 5 at 3:30












2 Answers
2






active

oldest

votes


















1














If you're wanting only a limited number of valid options, you should really consider using the Choice command. Unlike Set /P which allows for any or no entry, Choice will alert and prevent invalid input.



Set "velocidad=4"
Choice /C 123 /M "reduccion de velocidad: "
Set /A velocidad -= %ErrorLevel%


For usage information, enter Choice /? at the Command Prompt. And similarly for the Set command, Set /?.






share|improve this answer
























  • I dont know why but choice command just dont work for me

    – maxmarsz
    Jan 2 at 21:05











  • When I add it program just stops as it comes and I cannot do anything to it

    – maxmarsz
    Jan 2 at 21:06








  • 1





    It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

    – Compo
    Jan 2 at 22:17













  • So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

    – maxmarsz
    Jan 3 at 5:41











  • @maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

    – Compo
    Jan 3 at 6:25



















0














Just



set /a speed=4-speed


When you use /a, you don't need % anymore. also you used == instead of =.



If you want x-speed, then it's:



set /a speed=x-speed





share|improve this answer





















  • 2





    Thank you a lot It works :D

    – maxmarsz
    Jan 2 at 16:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010107%2fhow-to-reduce-value-of-variable-in-batch%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you're wanting only a limited number of valid options, you should really consider using the Choice command. Unlike Set /P which allows for any or no entry, Choice will alert and prevent invalid input.



Set "velocidad=4"
Choice /C 123 /M "reduccion de velocidad: "
Set /A velocidad -= %ErrorLevel%


For usage information, enter Choice /? at the Command Prompt. And similarly for the Set command, Set /?.






share|improve this answer
























  • I dont know why but choice command just dont work for me

    – maxmarsz
    Jan 2 at 21:05











  • When I add it program just stops as it comes and I cannot do anything to it

    – maxmarsz
    Jan 2 at 21:06








  • 1





    It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

    – Compo
    Jan 2 at 22:17













  • So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

    – maxmarsz
    Jan 3 at 5:41











  • @maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

    – Compo
    Jan 3 at 6:25
















1














If you're wanting only a limited number of valid options, you should really consider using the Choice command. Unlike Set /P which allows for any or no entry, Choice will alert and prevent invalid input.



Set "velocidad=4"
Choice /C 123 /M "reduccion de velocidad: "
Set /A velocidad -= %ErrorLevel%


For usage information, enter Choice /? at the Command Prompt. And similarly for the Set command, Set /?.






share|improve this answer
























  • I dont know why but choice command just dont work for me

    – maxmarsz
    Jan 2 at 21:05











  • When I add it program just stops as it comes and I cannot do anything to it

    – maxmarsz
    Jan 2 at 21:06








  • 1





    It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

    – Compo
    Jan 2 at 22:17













  • So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

    – maxmarsz
    Jan 3 at 5:41











  • @maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

    – Compo
    Jan 3 at 6:25














1












1








1







If you're wanting only a limited number of valid options, you should really consider using the Choice command. Unlike Set /P which allows for any or no entry, Choice will alert and prevent invalid input.



Set "velocidad=4"
Choice /C 123 /M "reduccion de velocidad: "
Set /A velocidad -= %ErrorLevel%


For usage information, enter Choice /? at the Command Prompt. And similarly for the Set command, Set /?.






share|improve this answer













If you're wanting only a limited number of valid options, you should really consider using the Choice command. Unlike Set /P which allows for any or no entry, Choice will alert and prevent invalid input.



Set "velocidad=4"
Choice /C 123 /M "reduccion de velocidad: "
Set /A velocidad -= %ErrorLevel%


For usage information, enter Choice /? at the Command Prompt. And similarly for the Set command, Set /?.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 18:12









CompoCompo

16.8k3927




16.8k3927













  • I dont know why but choice command just dont work for me

    – maxmarsz
    Jan 2 at 21:05











  • When I add it program just stops as it comes and I cannot do anything to it

    – maxmarsz
    Jan 2 at 21:06








  • 1





    It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

    – Compo
    Jan 2 at 22:17













  • So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

    – maxmarsz
    Jan 3 at 5:41











  • @maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

    – Compo
    Jan 3 at 6:25



















  • I dont know why but choice command just dont work for me

    – maxmarsz
    Jan 2 at 21:05











  • When I add it program just stops as it comes and I cannot do anything to it

    – maxmarsz
    Jan 2 at 21:06








  • 1





    It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

    – Compo
    Jan 2 at 22:17













  • So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

    – maxmarsz
    Jan 3 at 5:41











  • @maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

    – Compo
    Jan 3 at 6:25

















I dont know why but choice command just dont work for me

– maxmarsz
Jan 2 at 21:05





I dont know why but choice command just dont work for me

– maxmarsz
Jan 2 at 21:05













When I add it program just stops as it comes and I cannot do anything to it

– maxmarsz
Jan 2 at 21:06







When I add it program just stops as it comes and I cannot do anything to it

– maxmarsz
Jan 2 at 21:06






1




1





It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

– Compo
Jan 2 at 22:17







It won't work if you're still using the seventeen+ year old Operating System formerly known as Windows XP, as it wasn't part of that product. But I'm sure that you'd have mentioned that as part of your question proper, or at least use an appropriate title and/or tag to inform us you were using Windows XP if that was the case. Have you opened a Command Prompt window and entered Choice /? yet, if it works, the problem is elsewhere in something you haven't told us about, and therefore out of the scope of this question.

– Compo
Jan 2 at 22:17















So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

– maxmarsz
Jan 3 at 5:41





So Im working on windows 10 and yes I checkd the choice /? and it works. But when I use it in my program it just stops

– maxmarsz
Jan 3 at 5:41













@maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

– Compo
Jan 3 at 6:25





@maxmarsz, there is absolutely nothing wrong with the three lines I've posted. Please update the main body of your question to provide us with the actual code you're now having issues with. We cannot help you fix the problem if we don't know what it is.

– Compo
Jan 3 at 6:25













0














Just



set /a speed=4-speed


When you use /a, you don't need % anymore. also you used == instead of =.



If you want x-speed, then it's:



set /a speed=x-speed





share|improve this answer





















  • 2





    Thank you a lot It works :D

    – maxmarsz
    Jan 2 at 16:50
















0














Just



set /a speed=4-speed


When you use /a, you don't need % anymore. also you used == instead of =.



If you want x-speed, then it's:



set /a speed=x-speed





share|improve this answer





















  • 2





    Thank you a lot It works :D

    – maxmarsz
    Jan 2 at 16:50














0












0








0







Just



set /a speed=4-speed


When you use /a, you don't need % anymore. also you used == instead of =.



If you want x-speed, then it's:



set /a speed=x-speed





share|improve this answer















Just



set /a speed=4-speed


When you use /a, you don't need % anymore. also you used == instead of =.



If you want x-speed, then it's:



set /a speed=x-speed






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 16:50

























answered Jan 2 at 16:48









TiwTiw

4,24861630




4,24861630








  • 2





    Thank you a lot It works :D

    – maxmarsz
    Jan 2 at 16:50














  • 2





    Thank you a lot It works :D

    – maxmarsz
    Jan 2 at 16:50








2




2





Thank you a lot It works :D

– maxmarsz
Jan 2 at 16:50





Thank you a lot It works :D

– maxmarsz
Jan 2 at 16:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010107%2fhow-to-reduce-value-of-variable-in-batch%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Angular Downloading a file using contenturl with Basic Authentication

Olmecas

Can't read property showImagePicker of undefined in react native iOS