Why does the %1random% variable not work!?!?!

April 10, 2013 at 17:59:15
Specs: Windows Vista/7
:: I am trying to create a program that creates a series or random numbers and count all their
:: possibilities. You can create different numbers of series and choose whether numbers in the
:: series duplicate or not.
:: I worked on this on Windows 7, then I tried running this Windows Vista, I don't know if that is
:: the problem.
@echo off
mode 200,160
:start
echo.How many numbers do you want in your strings?
echo.
set /p #?=1-9:
echo.Do want the numbers in the string to repeat?
echo.
set /p r?=Y/N:
if /i %#?%==9 if /i %r?%==no goto 9/nr
if /i %#?%==8 if /i %r?%==no goto 8/nr
if /i %#?%==7 if /i %r?%==no goto 7/nr
if /i %#?%==6 if /i %r?%==no goto 6/nr
if /i %#?%==5 if /i %r?%==no goto 5/nr
if /i %#?%==4 if /i %r?%==no goto 4/nr
if /i %#?%==3 if /i %r?%==no goto 3/nr
if /i %#?%==2 if /i %r?%==no goto 2/nr
if /i %#?%==1 if /i %r?%==no goto 1/nr
if /i %#?%==9 if /i %r?%==yes goto 9
if /i %#?%==8 if /i %r?%==yes goto 8
if /i %#?%==7 if /i %r?%==yes goto 7
if /i %#?%==6 if /i %r?%==yes goto 6
if /i %#?%==5 if /i %r?%==yes goto 5
if /i %#?%==4 if /i %r?%==yes goto 4
if /i %#?%==3 if /i %r?%==yes goto 3
if /i %#?%==2 if /i %r?%==yes goto 2
if /i %#?%==1 if /i %r?%==yes goto 1
echo.One of the choices you made was not valid.
echo.
pause
goto start

:1
set arandom=%random:~-1%
pause
echo.%arandom% >> A.temp
for /f "tokens=*" %%a in (A.temp) do set 1random=%%a
if not exist Digit_1.txt echo. >> Digit_1.txt
findstr %1random% Digit_1.txt > nul
if %errorlevel% equ 0 goto 1
if %errorlevel% equ 1 echo.%1random% >> Digit_1.txt && echo.%1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random% %1random%
pause
goto 1

:2
set 2random=%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_2.txt echo. >> Digits_2.txt
findstr /i /c:"%2random%" C:\Users\%username%\Desktop\Digits_2.txt > nul
if %errorlevel% equ 0 goto 2
if %errorlevel% equ 1 echo.%2random% >> C:\Users\%username%\Desktop\Digits_2.txt && echo.%2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random% %2random%
goto 2


:3
set 3random=%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_3.txt echo. >> Digits_3.txt
findstr /i /c:"%3random%" C:\Users\%username%\Desktop\Digits_3.txt > nul
if %errorlevel% equ 0 goto 3
if %errorlevel% equ 1 echo.%3random% >> C:\Users\%username%\Desktop\Digits_3.txt && echo.%3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random% %3random%
goto 3

:4
set 4random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_4.txt echo. >> Digits_4.txt
findstr /i /c:"%4random%" C:\Users\%username%\Desktop\Digits_4.txt > nul
if %errorlevel% equ 0 goto 4
if %errorlevel% equ 1 echo.%4random% >> C:\Users\%username%\Desktop\Digits_4.txt && echo.%4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random% %4random%
goto 4

:5
set 5random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_5.txt echo. >> Digits_5.txt
findstr /i /c:"%5random%" C:\Users\%username%\Desktop\Digits_5.txt > nul
if %errorlevel% equ 0 goto 5
if %errorlevel% equ 1 echo.%5random% >> C:\Users\%username%\Desktop\Digits_5.txt && echo.%5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random% %5random%
goto 5

:6
set 6random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_6.txt echo. >> Digits_6.txt
findstr /i /c:"%6random%" C:\Users\%username%\Desktop\Digits_6.txt > nul
if %errorlevel% equ 0 goto 6
if %errorlevel% equ 1 echo.%6random% >> C:\Users\%username%\Desktop\Digits_6.txt && echo.%6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random% %6random%
goto 6

:7
set 7random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_7.txt echo. >> Digits_7.txt
findstr /i /c:"%7random%" C:\Users\%username%\Desktop\Digits_7.txt > nul
if %errorlevel% equ 0 goto 7
if %errorlevel% equ 1 echo.%7random% >> C:\Users\%username%\Desktop\Digits_7.txt && echo.%7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random% %7random%
goto 7

:8
set 8random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_8.txt echo. >> Digits_8.txt
findstr /i /c:"%8random%" C:\Users\%username%\Desktop\Digits_8.txt > nul
if %errorlevel% equ 0 goto 8
if %errorlevel% equ 1 echo.%8random% >> C:\Users\%username%\Desktop\Digits_8.txt && echo.%8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random% %8random%
goto 8

:9
set 9random=%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%%random:~-0,1%
if not exist C:\Users\%username%\Desktop\Digits_8.txt echo. >> Digits_9.txt
findstr /i /c:"%9random%" C:\Users\%username%\Desktop\Digits_9.txt > nul
if %errorlevel% equ 0 goto 9
if %errorlevel% equ 1 echo.%9random% >> C:\Users\%username%\Desktop\Digits_9.txt && echo.%9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random% %9random%
goto 9

:1/nr
goto 1/nr/1
:1/nr/1
set rand1=%random:~-0,1%
set random1=%rand1%
if not exist C:\Users\%username%\Desktop\1_Digit.txt echo. >> 1_Digit.txt
findstr /i /c:"%random1%" C:\Users\%username%\Desktop\1_Digit.txt > nul
if %errorlevel% equ 0 goto 1 - nr
if %errorlevel% equ 1 echo.%random1% >> C:\Users\%username%\Desktop\1_Digit.txt && echo.%random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1% %random1%
goto 1/nr

:2/nr
goto 2 - nr/1
:2 - nr/1
set rand1=%random:~-0,1%
:2 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 2 - nr/2
set random2=%rand1%%rand2%
if not exist C:\Users\%username%\Desktop\2_Digits.txt echo. >> 2_Digits.txt
findstr /i /c:"%random2%" C:\Users\%username%\Desktop\2_Digits.txt > nul
if %errorlevel% equ 0 goto 2 - nr
if %errorlevel% equ 1 echo.%random2% >> C:\Users\%username%\Desktop\2_Digits.txt && echo.%random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2% %random2%
goto 2 - nr

:3/nr
goto 3 - nr/1
:3 - nr/1
set rand1=%random:~-0,1%
:3 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 3 - nr/2
:3 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 3 - nr/3
if "%rand3%"=="%rand2%" goto 3 - nr/3
set random3=%rand1%%rand2%%rand3%
if not exist C:\Users\%username%\Desktop\3_Digits.txt echo. >> 3_Digits.txt
findstr /i /c:"%random3%" C:\Users\%username%\Desktop\3_Digits.txt > nul
if %errorlevel% equ 0 goto 3 - nr
if %errorlevel% equ 1 echo.%random3% >> C:\Users\%username%\Desktop\3_Digits.txt && echo.%random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3% %random3%
goto 3 - nr

:4/nr
goto 4 - nr/1
:4 - nr/1
set rand1=%random:~-0,1%
:4 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 4 - nr/2
:4 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 4 - nr/3
if "%rand3%"=="%rand2%" goto 4 - nr/3
:4 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 4 - nr/4
if "%rand4%"=="%rand2%" goto 4 - nr/4
if "%rand4%"=="%rand3%" goto 4 - nr/4
set random4=%rand1%%rand2%%rand3%%rand4%
if not exist C:\Users\%username%\Desktop\4_Digits.txt echo. >> 4_Digits.txt
findstr /i /c:"%random4%" C:\Users\%username%\Desktop\4_Digits.txt > nul
if %errorlevel% equ 0 goto 4 - nr
if %errorlevel% equ 1 echo.%random4% >> C:\Users\%username%\Desktop\4_Digits.txt && echo.%random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4% %random4%
goto 4 - nr

:5/nr
goto 5 - nr/1
:5 - nr/1
set rand1=%random:~-0,1%
:5 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 5 - nr/2
:5 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 5 - nr/3
if "%rand3%"=="%rand2%" goto 5 - nr/3
:5 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 5 - nr/4
if "%rand4%"=="%rand2%" goto 5 - nr/4
if "%rand4%"=="%rand3%" goto 5 - nr/4
:5 - nr/5
set rand5=%random:~-0,1%
if "%rand5%"=="%rand1%" goto 5 - nr/5
if "%rand5%"=="%rand2%" goto 5 - nr/5
if "%rand5%"=="%rand3%" goto 5 - nr/5
if "%rand5%"=="%rand4%" goto 5 - nr/5
set random5=%rand1%%rand2%%rand3%%rand4%%rand5%
if not exist C:\Users\%username%\Desktop\5_Digits.txt echo. >> 5_Digits.txt
findstr /i /c:"%random5%" C:\Users\%username%\Desktop\5_Digits.txt > nul
if %errorlevel% equ 0 goto 5 - nr
if %errorlevel% equ 1 echo.%random5% >> C:\Users\%username%\Desktop\5_Digits.txt && echo.%random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5% %random5%
goto 5 - nr

:6/nr
goto 6 - nr/1
:6 - nr/1
set rand1=%random:~-0,1%
:6 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 6 - nr/2
:6 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 6 - nr/3
if "%rand3%"=="%rand2%" goto 6 - nr/3
:6 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 6 - nr/4
if "%rand4%"=="%rand2%" goto 6 - nr/4
if "%rand4%"=="%rand3%" goto 6 - nr/4
:6 - nr/5
set rand5=%random:~-0,1%
if "%rand5%"=="%rand1%" goto 6 - nr/5
if "%rand5%"=="%rand2%" goto 6 - nr/5
if "%rand5%"=="%rand3%" goto 6 - nr/5
if "%rand5%"=="%rand4%" goto 6 - nr/5
:6 - nr/6
set rand6=%random:~-0,1%
if "%rand6%"=="%rand1%" goto 6 - nr/6
if "%rand6%"=="%rand2%" goto 6 - nr/6
if "%rand6%"=="%rand3%" goto 6 - nr/6
if "%rand6%"=="%rand4%" goto 6 - nr/6
if "%rand6%"=="%rand5%" goto 6 - nr/6
set random6=%rand1%%rand2%%rand3%%rand4%%rand5%%rand6%
if not exist C:\Users\%username%\Desktop\6_Digits.txt echo. >> 6_Digits.txt
findstr /i /c:"%random6%" C:\Users\%username%\Desktop\6_Digits.txt > nul
if %errorlevel% equ 0 goto 6 - nr
if %errorlevel% equ 1 echo.%random6% >> C:\Users\%username%\Desktop\6_Digits.txt && echo.%random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6% %random6%
goto 6 - nr

:7/nr
goto 7 - nr/1
:7 - nr/1
set rand1=%random:~-0,1%
:7 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 7 - nr/2
:7 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 7 - nr/3
if "%rand3%"=="%rand2%" goto 7 - nr/3
:7 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 7 - nr/4
if "%rand4%"=="%rand2%" goto 7 - nr/4
if "%rand4%"=="%rand3%" goto 7 - nr/4
:7 - nr/5
set rand5=%random:~-0,1%
if "%rand5%"=="%rand1%" goto 7 - nr/5
if "%rand5%"=="%rand2%" goto 7 - nr/5
if "%rand5%"=="%rand3%" goto 7 - nr/5
if "%rand5%"=="%rand4%" goto 7 - nr/5
:7 - nr/6
set rand6=%random:~-0,1%
if "%rand6%"=="%rand1%" goto 7 - nr/6
if "%rand6%"=="%rand2%" goto 7 - nr/6
if "%rand6%"=="%rand3%" goto 7 - nr/6
if "%rand6%"=="%rand4%" goto 7 - nr/6
if "%rand6%"=="%rand5%" goto 7 - nr/6
:7 - nr/7
set rand7=%random:~-0,1%
if "%rand7%"=="%rand1%" goto 7 - nr/7
if "%rand7%"=="%rand2%" goto 7 - nr/7
if "%rand7%"=="%rand3%" goto 7 - nr/7
if "%rand7%"=="%rand4%" goto 7 - nr/7
if "%rand7%"=="%rand5%" goto 7 - nr/7
if "%rand7%"=="%rand6%" goto 7 - nr/7
set random7=%rand1%%rand2%%rand3%%rand4%%rand5%%rand6%%rand7%
if not exist C:\Users\%username%\Desktop\7_Digits.txt echo. >> 7_Digits.txt
findstr /i /c:"%random7%" C:\Users\%username%\Desktop\7_Digits.txt > nul
if %errorlevel% equ 0 goto 7 - nr
if %errorlevel% equ 1 echo.%random7% >> C:\Users\%username%\Desktop\7_Digits.txt && echo.%random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7% %random7%
goto 7 - nr

:8/nr
goto 8 - nr/1
:8 - nr/1
set rand1=%random:~-0,1%
:8 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 8 - nr/2
:8 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 8 - nr/3
if "%rand3%"=="%rand2%" goto 8 - nr/3
:8 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 8 - nr/4
if "%rand4%"=="%rand2%" goto 8 - nr/4
if "%rand4%"=="%rand3%" goto 8 - nr/4
:8 - nr/5
set rand5=%random:~-0,1%
if "%rand5%"=="%rand1%" goto 8 - nr/5
if "%rand5%"=="%rand2%" goto 8 - nr/5
if "%rand5%"=="%rand3%" goto 8 - nr/5
if "%rand5%"=="%rand4%" goto 8 - nr/5
:8 - nr/6
set rand6=%random:~-0,1%
if "%rand6%"=="%rand1%" goto 8 - nr/6
if "%rand6%"=="%rand2%" goto 8 - nr/6
if "%rand6%"=="%rand3%" goto 8 - nr/6
if "%rand6%"=="%rand4%" goto 8 - nr/6
if "%rand6%"=="%rand5%" goto 8 - nr/6
:8 - nr/7
set rand7=%random:~-0,1%
if "%rand7%"=="%rand1%" goto 8 - nr/7
if "%rand7%"=="%rand2%" goto 8 - nr/7
if "%rand7%"=="%rand3%" goto 8 - nr/7
if "%rand7%"=="%rand4%" goto 8 - nr/7
if "%rand7%"=="%rand5%" goto 8 - nr/7
if "%rand7%"=="%rand6%" goto 8 - nr/7
:8 - nr/8
set rand8=%random:~-0,1%
if "%rand8%"=="%rand1%" goto 8 - nr/8
if "%rand8%"=="%rand2%" goto 8 - nr/8
if "%rand8%"=="%rand3%" goto 8 - nr/8
if "%rand8%"=="%rand4%" goto 8 - nr/8
if "%rand8%"=="%rand5%" goto 8 - nr/8
if "%rand8%"=="%rand6%" goto 8 - nr/8
if "%rand8%"=="%rand7%" goto 8 - nr/8
set random8=%rand1%%rand2%%rand3%%rand4%%rand5%%rand6%%rand7%%rand8%
if not exist C:\Users\%username%\Desktop\8_Digits.txt echo. >> 8_Digits.txt
findstr /i /c:"%random8%" C:\Users\%username%\Desktop\8_Digits.txt > nul
if %errorlevel% equ 0 goto 8 - nr
if %errorlevel% equ 1 echo.%random8% >> C:\Users\%username%\Desktop\8_Digits.txt && echo.%random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8% %random8%
goto 8 - nr

:9/nr
goto 9 - nr/1
:9 - nr/1
set rand1=%random:~-0,1%
:9 - nr/2
set rand2=%random:~-0,1%
if "%rand2%"=="%rand1%" goto 9 - nr/2
:9 - nr/3
set rand3=%random:~-0,1%
if "%rand3%"=="%rand1%" goto 9 - nr/3
if "%rand3%"=="%rand2%" goto 9 - nr/3
:9 - nr/4
set rand4=%random:~-0,1%
if "%rand4%"=="%rand1%" goto 9 - nr/4
if "%rand4%"=="%rand2%" goto 9 - nr/4
if "%rand4%"=="%rand3%" goto 9 - nr/4
:9 - nr/5
set rand5=%random:~-0,1%
if "%rand5%"=="%rand1%" goto 9 - nr/5
if "%rand5%"=="%rand2%" goto 9 - nr/5
if "%rand5%"=="%rand3%" goto 9 - nr/5
if "%rand5%"=="%rand4%" goto 9 - nr/5
:9 - nr/6
set rand6=%random:~-0,1%
if "%rand6%"=="%rand1%" goto 9 - nr/6
if "%rand6%"=="%rand2%" goto 9 - nr/6
if "%rand6%"=="%rand3%" goto 9 - nr/6
if "%rand6%"=="%rand4%" goto 9 - nr/6
if "%rand6%"=="%rand5%" goto 9 - nr/6
:9 - nr/7
set rand7=%random:~-0,1%
if "%rand7%"=="%rand1%" goto 9 - nr/7
if "%rand7%"=="%rand2%" goto 9 - nr/7
if "%rand7%"=="%rand3%" goto 9 - nr/7
if "%rand7%"=="%rand4%" goto 9 - nr/7
if "%rand7%"=="%rand5%" goto 9 - nr/7
if "%rand7%"=="%rand6%" goto 9 - nr/7
:9 - nr/8
set rand8=%random:~-0,1%
if "%rand8%"=="%rand1%" goto 9 - nr/8
if "%rand8%"=="%rand2%" goto 9 - nr/8
if "%rand8%"=="%rand3%" goto 9 - nr/8
if "%rand8%"=="%rand4%" goto 9 - nr/8
if "%rand8%"=="%rand5%" goto 9 - nr/8
if "%rand8%"=="%rand6%" goto 9 - nr/8
if "%rand8%"=="%rand7%" goto 9 - nr/8
:9 - nr/9
set rand9=%random:~-0,1%
if "%rand9%"=="%rand1%" goto 9 - nr/9
if "%rand9%"=="%rand2%" goto 9 - nr/9
if "%rand9%"=="%rand3%" goto 9 - nr/9
if "%rand9%"=="%rand4%" goto 9 - nr/9
if "%rand9%"=="%rand5%" goto 9 - nr/9
if "%rand9%"=="%rand6%" goto 9 - nr/9
if "%rand9%"=="%rand7%" goto 9 - nr/9
if "%rand9%"=="%rand8%" goto 9 - nr/9
set random9=%rand1%%rand2%%rand3%%rand4%%rand5%%rand6%%rand7%%rand8%%rand9%
if not exist C:\Users\%username%\Desktop\9_Digits.txt echo. >> 9_Digits.txt
findstr /i /c:"%random9%" C:\Users\%username%\Desktop\9_Digits.txt > nul
if %errorlevel% equ 0 goto 9 - nr
if %errorlevel% equ 1 echo.%random9% >> C:\Users\%username%\Desktop\9_Digits.txt && echo.%random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9% %random9%
goto 9 - nr


See More: Why does the %1random% variable not work!?!?!

Report •


#1
April 10, 2013 at 18:26:25
Using a ? in a var name seems like a bad idea.

Doing a /i test for a number... no point.

If r gets set to Y or N it will never equal no.

W2K [and maybe newer] has a buit-in RANDOM.

You can save lotsa typing and lotsa mess. {And up your odds of getting help.] [404 lines LOL]

by replacing this stuff:
if /i %#?%==9 if /i %r?%==no goto 9/nr

set R
set A
goto :!R!!A!

=====================
M2 Golden-Triangle


Report •

#2
April 10, 2013 at 19:31:32
In computer school (30 years ago) they always said: "If you see a repeating pattern, of code, make it into a loop. That's what loops are for." ;-)
Here's an application of that principle:

@echo off & setlocal enabledelayedexpansion
set /p lng=length of the number:
set /p norep=unique digits? (u for unique):
for /L %%i in (1,1,%lng%) do (
call :try_agin
)
echo %x%
goto :eof

:try_agin
set z=%random:~-1%
:: oops, lost a percent in translation:
::if /i "norep%" neq "u" goto :nu
if /i "%norep%" neq "u" goto :nu
if not defined x goto :nu
set test=!x:%z%=!
if "%test%" neq "%x%" goto :try_agin
:nu
set x=%x%%z%
::==== end
Thanks, H, for re-testing my code! I hate it when this happens! :-(
w2k is probably windows 2000


Report •

#3
April 11, 2013 at 09:53:57
Sorry, that last batch does not work (I typed 9 then I typed u).

Ok, so when I isolate 9/nr it works but when I try to navigate to it in the larger program, it does not work. So it is not a Windows Vista/7 thing because I am now working on the Windows 7 computer and it still does not work.
I do understand what the first respondant was saying about using odd characters but trust me, I have tested using this as a variable so many times and it does not affect anything unless it is a | () ^ > < ~ ` {} [] - + = " * % or a ! mainly because those have special functions.

Also I did not set the variable to Y or N, that is only what I prompt the user with.
I am trying to stay away from the setlocal command because I don't understand it at all.

What is W2K?


Report •

Related Solutions

#4
April 11, 2013 at 14:47:16
Hello H: I would strongly recommend using setlocal unless you specifically intend for variables to be global. When you run without it, your variables can "persist", that is, continue to hold old values when you don't intend. Here's a batch I wrote that dodges setlocal, but note that subroutine "clear" must be present or the batch will fail on subsequent runs:
@echo off
::note these will still have old values if :clear is not called!
set a
pause
call :clear
set /p lng=length of the number:
set /p norep=unique digits? (u for unique):
for /L %%i in (1,1,%lng%) do (
call :try_agin
)
echo %x%
goto :clear

:try_agin
set z=%random:~-1%
if /i "%norep%" neq "u" goto :nu
if not defined x goto :nu
if defined a%z% goto :try_agin
:nu
set a%z%=1
set x=%x%%z%
goto :eof

:clear
:: enable the following line to see what I mean...
rem goto :eof
for /L %%a in (0,1,9) do set a%%a=
set z=
set x=
set lng=
set norep=
::====== end batch
Ok, so try running this without using the "clear" routine. The first time, it might work,
but see what happens the second time you run it: all the variables still have their values left over from the first run until and unless you explicitly clear them. (This might be what's going wrong with your original code...) Oh, and another thing that you should always always and without fail do is to pre-clear any variable that is used in a "set /p" statement, (like I forgot to do in post #2!), for the same reason: it will retain whatever garbage happens to be in it if the user hits [ENTER] with no data:
:10 echo x:%x%
set /p x=whatever:
echo x after set-P:%x%
goto :10

put in some garbage, then put in a null ENTER, and you will see how it keeps the garbage intact. This has driven me to madness and total confusion in the past when I forgot to do it.


Report •

#5
April 11, 2013 at 21:12:37
That last post completely confused me.
So, why is it that when I turn echo on and tell it to echo %variable% into a document and echo %variable% %variable% %variable%... all in one line it does not work when that part of the file is separated from the rest. Could it be that my labels are too long? I just read somewhere that labels can only be up to eight characters in length.

Report •

#6
April 12, 2013 at 19:03:15
Ok, here's about my last take on this thing:
if %errorlevel% equ 1 echo.%random9% >> C:\Users\%username%\Desktop\9_Digits.txt && echo.%random9%

Does directory "c:\users\%username%\desktop" exist? if not, an error msg should show up, but your && will definitely not be executed if it does not. (&& code only executes if errorlevel is zero)

And I believe the limit on label-names is no longer 8 bytes (from testing), but i don't know what it is and it probably doesn't matter.


Report •

#7
April 13, 2013 at 01:35:53
OP, I think you should start a new thread and clearly state objective.

nbrane, I think the label length [and allowed chars etc] needs study. I keep meaning to do it, but...

=====================
M2 Golden-Triangle


Report •

#8
April 13, 2013 at 19:55:38
@M2:
I became curious, so I ran tests (I figured a binarily even number, guessed at 128)
which it is (including the colon, but not including surrounding quotes).
If you use surrounding quotes, you can use spaces, but otherwise (of course), not.(since label is then being parsed as arguments). Not the comma though. It always "hacks" the label at the comma-point (so far in my tests). Colons are allowed except when doubled at the very start. That's as far as I've gone with allowable char.s, but I'm sure it's easily find-outable at MSDN or other googled sites.

Report •

#9
April 13, 2013 at 20:06:56
When I just take off all but one %random9% in the last echo, it works, but when I put more on it acts up.
Its not a space issue because it did the same thing with only two %random9%'s.
I know that the username works.

Report •

#10
April 14, 2013 at 19:17:13
You must be having some other problem, since the out-take (the lines you mentioned having failed) worked fine on both my xp and my 7. The number was echoed to a file and then echoed 18 times to the console (using a random, in my tests, 10-digit number). I didn't try it on Vista, but I doubt that's the problem.

Report •


Ask Question