0

so i made a loading screen but it doesnt work and i cant figure it out heres the code:

@echo off
:start
set a=10
pause
set 1=_
set 2=_
set 3=_
set 4=_
set 5=_
set 6=_
set 7=_
set 8=_
set 9=_
set 10=_
:b
cls
echo %a%
if %a%==10 goto 1
if %a%==20 goto 2
if %a%==30 goto 3
if %a%==40 goto 4
if %a%==50 goto 5
if %a%==60 goto 6
if %a%==70 goto 7
if %a%==80 goto 8
if %a%==90 goto 9
if %a%==100 goto 10
:1
set 1=#
goto echo
:2
set 2=#
goto echo
:3
set 3=#
goto echo
:4
set 4=#
goto echo
:5
set 5=#
goto echo
:6
set 6=#
goto echo
:7
set 7=#
goto echo
:8
set 8=#
goto echo
:9
set 9=#
goto echo
:10
set 10=#
goto echo
:echo
echo %1% %2% %3% %4% %5% %6% %7% %8% %9% %10%
set /a a+=10
TIMEOUT 1 >null
cls
goto b

so if anyone figures it out im very thank ful for answers i just cant understand why it would not work....

thanks :)

3 Answers3

2

%n where n is a single digit is interpreted by batch to mean 'this parameter number to the batch or procedure'.

Hence, echo %n% does nt work as you expect.

Futhermore, echo is a keyword and hence a poor choice for a label.

And the device is nul, not null. You'll find that you have created a file called null from this code.

Magoo
  • 77,302
  • 8
  • 62
  • 84
0

OK im not quite sure what's wrong but if you want a relay good looking loading screen use this http://www.battoexeconverter.com/ It allows you to compile your bat file to an exe. but more to the point it has some advanced commands that will allow you to make a good loading screen. see the sample codes when you install it. They are in a tab at the top.

09stephenb
  • 9,358
  • 15
  • 53
  • 91
0

As mentioned before, the main problem with your code is that a variable name can not start with digit, because %digit-restOfName% will always be expanded as %digit=Batch file parameter, followed by -restOfName.... However, I would like to present you some other points:

  • When several lines of code are repeated varying just a numeric value (or a series of any given values), you may "compress" the lines in just one line placed into a for command that will execute it with each one of the values.
  • Several variables that have the same name, but a varying number ("subscript") comprises an array that may also be managed via a for command.
  • You may use the value of a variable (or substring part) at any place in a Batch program, excepting a label. This feature may be used to write much shorter code via "tricks"; for example: goto %labelVar%.

The Batch file below is your original code modified accordingly to these ideas:

@echo off
:start
set a=10
pause
for /L %%i in (1,1,10) do set v%%i=_
:b
cls
echo %a%
set v%a:~0,-1%=#
echo %v1% %v2% %v3% %v4% %v5% %v6% %v7% %v8% %v9% %v10%
set /a a+=10
TIMEOUT 1 >nul
cls
goto b
Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108