Solved help me understand the batch query

May 18, 2017 at 22:37:35
Specs: Windows 7
My application receive a file daily with some version and then processed by a batch script. The batch script was good till the version of the file was 999. Now it's giving error as " Invalid number. Numbers are limited to 32-bits of precision."

The batch script where this set up version are given below

for /l %%a in (1,1,31) do if "!Version:~-1!"==" " set Version=!Version:~0,-1!

for /f "tokens=1,2 delims=." %%a in ("%Version%") do set /A MajorVersion=1000000%%a %% 1000000&set /A MinorVersion=1000000%%b %% 1000000

Please help me to explain the above batch script code and why we are getting error?

message edited by rkptcs

See More: help me understand the batch query

Report •

May 18, 2017 at 23:41:06
A bit hazy without seeing more of it but my guess is your set/a fails because it trying to do a mod 0
Such as:
set /a z=44%%0

You can confirm by putting ECHO in front of that line and a PAUSE on the next line and watching.


M2 Get custom script or take private lessons

Report •

May 19, 2017 at 05:53:42
✔ Best Answer
That's the overflow error. Either 1000000%%a or 1000000%%b ends up greater than 2,147,483,647.

EDIT: I used to have a trick for normalizing numbers this back when I was more involved with batch. I seem to remember it went something like this:

SET var=12345
SET var=000000000%var%
SET /A var=1%var:~-9% - 1000000000
@ECHO %var%

But then someone pointed out this, which is easier:

SET var=0000012345
FOR /F "tokens=* delims=0" %%a IN ("%var%") DO SET var=%%a

How To Ask Questions The Smart Way

message edited by Razor2.3

Report •

May 19, 2017 at 20:19:16
The whole concept is flawed, IMO, and should be ditched and start over. I don't know why modulo is required to sort this out. A sample of the latest version number, verbatim as recieved, would be most helpful. Looks to me like text, vs math, manipulation would be better, OR different math.
ps: sorry, see Razor's response, same idea. And anything with leading zero is treated as octal by batch, so be careful with batch math, as well as "divide-by-0" overflow dangers as M2 pointed out.

message edited by nbrane

Report •
Related Solutions

Ask Question