Missing operand... Batch Problem

November 16, 2010 at 16:45:29
Specs: Windows 7
I'm new here, and I've been working on a Batch Script that generates a number between a maximum and minimum number. Here is the script (or most of it):

echo Choose the Minimum Number (Must be over -1):
set /p min =
pause>nul
echo Choose the Maximum Number (Must be under 32768):
set /p max =
pause>nul
set /a range= %max% - %min%
set minrand = 0
set maxrand = 32767
set /a number = (%random%-%minrand%) * %range% \ %maxrand% + %min%
echo %number%

When I run it I get this error message:
Missing Operand.
ECHO is off.

What's wrong?


See More: Missing operand... Batch Problem

Report •


#1
November 16, 2010 at 19:48:45
set /p min = / set /p max =
set /a number = (%random%-%minrand%) * %range% \ %maxrand% + %min%
You forgot to change these two variables.

How To Ask Questions The Smart Way


Report •

#2
November 16, 2010 at 20:20:49
You mean put a /a before the variable when I set them?

Report •

#3
November 16, 2010 at 20:33:30
set /p min =
...
set /p max = 

Remove the spaces before "=". You presumably want variables named "min" and "max", but you are asking for "min " and "max ".


Report •

Related Solutions

#4
November 16, 2010 at 20:39:18
thanx. I'll try it real quick

Report •

#5
November 16, 2010 at 20:48:49
Edit

Disregard this post , it wasn't well thought through....


Report •

#6
November 16, 2010 at 20:49:23
OK, I tried it but now I get another error:
Missing operator.

What's wrong this time?

echo Choose the Minimum Number (Must be over -1):
set /p min=
pause>nul
echo Choose the Maximum Number (Must be under 32768):
set /p max=
pause>nul
set /a range=%max%-%min%
set minrand=0
set maxrand=32767
set /a number=(%random%-%minrand%)*%range%\%maxrand%+%min%
echo %number%


Report •

#7
November 16, 2010 at 20:54:03
I tried your way, Judago, but it doesn't work. When I put in 50 and 52 for Min/Max it returned 152. I think my way is correct (although it's not necessarily mine), but I just need to get it to work... :(

Report •

#8
November 16, 2010 at 20:59:25
Another Question:
Does anyone know how to do for loops in Batch? I'm used to Python, and I'm pretty new to Batch (although technically Batch is not a programming language...), so I was just wondering...

Report •

#9
November 16, 2010 at 21:04:10
I have no idea why "set /a" spits out an error, the sum *looks* valid.


I had the logic mixed up with #5, try this instead.

set /a number=(%random% %% ((max - min) + 1 )) + min


As for the for loops there are a couple of types in batch "for /?" from the command line will show some basic help.


Report •

#10
November 16, 2010 at 21:18:30
Awesome! It works! Thanks!
As for the for loops, thanks also.

Report •

#11
November 16, 2010 at 21:23:09
No problem!

If you feel like reading a long tutorial about batch for loops, I wrote this a while ago...

http://judago.webs.com/forloopmadne...


Report •

#12
November 17, 2010 at 21:20:29
I've been having some other problems with writing to a txt file using Batch. I have to go right now, I'll post more on it tmrw.

Report •

#13
November 23, 2010 at 11:59:22
Hey guys, I'm having another problem... for some reason, my computer/command line does not recognize the EDIT command. Could this be a Windows 7 problem? If so, how could I make it work?

P.S. if nobody answers I'll make a new thread


Report •


Ask Question