What's wrong with this code?

November 16, 2011 at 21:21:43
Specs: Windows 7
It's supposed to make typing text... This is how it looks executed:
linea:~-1,!numa!_
lineb:~-1,!numb!

Key:
linea=first line
numa=number of characters to display
numaa=number of total characters
same for b

And this is the code:
@echo off
SetLocal EnableDelayedExpansions
:nameless_set
set linea=Test test test test test test test!?.
set numa=0
set numaa=37
set lineb=Test test test test test test test!?
set numb=0
set numbb=36
:nameless
cls
echo %linea:~-1,!numa!%_
echo.%lineb:~-1,!numb!%
if not %numa% == %numaa% (
set /a numa+=1) else (
if not %numb% == %numbb% (
set /a numb+=1) else (
goto nameless_end))
ping 1.1.1.1 -n 1 -w 200 >nul
goto nameless
:nameless_end
cls
echo %linea%
echo.%lineb%
pause >nul
exit

I'm trying to shorten this:
cls
echo _
echo.
ping 1.1.1.1 -n 0.5 -w 200 >nul
cls
echo T_
echo.
ping 1.1.1.1 -n 0.5 -w 200 >nul
cls
echo Te_
echo.
ping 1.1.1.1 -n 0.5 -w 200 >nul
cls
echo Tes_
echo.
ping 1.1.1.1 -n 0.5 -w 200 >nul
cls
echo Test_
echo.
ping 1.1.1.1 -n 0.5 -w 200 >nul
...

Also I would like to be able to use variables in the typing text so this:
set linea=Hello %name%!
will work thus I need some code that will retrieve the amount of characters and save it as %numaa%


See More: Whats wrong with this code?

Report •

#1
November 17, 2011 at 02:27:12
Well, I admit I did not walk throgh your (cumbersome) script but at first glance I noticed

SetLocal EnableDelayedExpansions

should be

SetLocal EnableDelayedExpansion

More when you code dynamic variables the ! must embrace the %, i.e.

echo %linea:~-1,!numa!%_
echo.%lineb:~-1,!numb!%

should be

echo !linea:~-1,%numa%!_
echo.!lineb:~-1,%numb%!

and never use ! as quotation mark with dynamic variables since now it is interpreted as a special symbol, i.e. no at all e.g. echo. DONE!.

Report •

#2
November 17, 2011 at 11:42:20
@IVO thanks I will try to fix it and tell you my results! Also will it be ok if I used ^! ?
Also scroll to the very bopttom of my pst and read the last passage.
Now it looks like:
._
lineb:~-1,0


Report •

#3
November 18, 2011 at 03:55:59
Yes, you can escape the ! by typing a caret i.e. ^! if you need to use it as an ordinary quotation mark, but I suggest you always try to exploit the most straightforward code and that is an heavy way to write conversation strings.

Please, post again your corrected code so I can take a look at it since I guess there are other bugs.


Report •
Related Solutions


Ask Question