how i can declare the large variable in dos

March 15, 2011 at 09:50:19
Specs: Windows XP
how we can use large variable in DOS
exampleset var =1050071000

for /l %a in (var,1,1050071110) do set var=%a
but result is not correct

See More: how i can declare the large variable in dos

Report •

March 15, 2011 at 10:49:33
I think you can do this...

Set Var = 1050071100
For /L %A IN (%var%,1,1050071110) DO (
  Set Var2=%a
  Echo %var2%

*Not tested*

If the For command has a limit then there is nothing you can do except put your set in a TXT file and use the file in your for command.

Report •

March 15, 2011 at 10:55:29
Aa there is no DOS in Windows XP you cannot do anything in DOS with Windows XP.

I assume you are using a batch file from the command prompt, which is not DOS.

As Windows XP is a 32 bit operating system, the highest value variable you can use is 4,294,967,295. Your variable will be truncated to 32 bits if it doesn't throw an overflow error. There are ways around this in high level languages but it involves some complicated bit manipulation that is way beyond the abilities of a batch file.


Report •

March 15, 2011 at 12:01:24
StuartS: the highest value variable you can use is 4,294,967,295
Small nitpick, but the variables are signed, so the biggest native number is half that.

You need to either remove the spaces on the SET, or use the /A switch.

How To Ask Questions The Smart Way

Report •

Related Solutions

March 15, 2011 at 12:45:11
You can do a garden variety SET to a very long string of nums.

As R2 says, an ARITHMRTIC SET has a limit.

BUT [Here comes the but part.] a for /L will treat it as a number.

:: ==========================================
:: bigset.bat Wed 16-03-2011 2:33:27.66
@echo off & setLocal enableDELAYedeXpansioN

set z=429496729
for /L %%a in (!z!,1,429496733) do (
echo %%a

Life is too important to be taken seriously.


Report •

March 15, 2011 at 16:18:22
You could use string based maths, but it's slower and not pretty:

@echo off
rem Tested on xp home

SetLocal EnableDelayedExpansion
set start=564654656579879798798000
set end=564654656579879798799000

if not "!start!"=="!end!" (
    call :increment !start! start
    echo !start!
    goto loop

goto :eof
SetLocal EnableDelayedExpansion
set input_num="%~1"
if %input_num%=="" set input_num="<no input>"
if "%~2"=="" set input_num="!input_num:"=! "
for /f "delims=0123456789" %%a in (%input_num%) do (
    echo ....----====**** ERROR ****====----....
    echo Inputs   : "%~1" "%~2"
    echo Should be: integer variable_name
    goto :eof
) > con
set input_num=%input_num:"=%
for /l %%a in (0 1 9) do set input_num=!input_num:%%a= %%a!
for %%a in (reverse_num result_num done temp_num) do set %%a=
for %%a in (%input_num%) do set reverse_num=%%a !reverse_num!
for %%a in (%reverse_num%) do (
    if defined done (
        set result_num=%%a!result_num!
    ) else (
        if %%a==9 (
            set result_num=0!result_num!
        ) else (
            set /a temp_num=%%a + 1
            set result_num=!temp_num!!result_num!
            set done=1
if not defined done set result_num=1%result_num%
    set %~2=%result_num%

Report •

Ask Question