1.

Solve : exit /b turning echo off?

Answer»

For some reason exit /b is leaving echo off when the program ends. Is there anyway to fix this?
(:end is at the bottom)
Code: [Select]:: version 3.5
@echo off
if "%1"=="-debug" (
shift
echo on
)
setlocal EnableDelayedExpansion

REM Clear Var
call :clearVar

REM Declare default signs
set cordinate=+
set space=-
set zero=0


REM Find the number of arguments
set num_args=0
:loop
set findArg_value=%1
set f | find "%findArg_value%" 1>nul 2>&1
if "%errorlevel%"=="0" (
set /a num_args+=1
set arg!num_args!=%1
shift
goto loop )
set findArg_value=


REM Check for modifyers
goto :Modifyers.start

:Modifyers.end


REM Seperate coordinates into X and Y values
set a=0
set error=0
:find_argX/argY
set /a a+=1
for /f "tokens=1,2 delims=." %%B in ('call echo !arg%a%!') do (
call :sep_cord %%B %%C
)
goto :end.sep_cord
:sep_cord
set argX%a%=%1
set argY%a%=%2
if not defined argX%a% set error=1
if not defined argY%a% set error=1
goto :eof
:end.sep_cord
if "%error%"=="1" goto :help
if not "%num_args%"=="%a%" goto :find_argX/argY
set a=
set error=

REM Find the max X and Y values
set argX_max=0
set argY_max=0
set a=0
:find_argX.max/argY.max
set /a a+=1
call set workingArgX=!argX%a%!
call set workingArgY=!argY%a%!
if %workingArgX% GTR %argX_max% set argX_max=%workingArgX%
if %workingArgY% GTR %argY_max% set argY_max=%workingArgY%
if not "%a%"=="%num_args%" goto :find_argX.max/argY.max
set workingArgX=
set workingArgY=
set a=

REM Find the min X and Y values
set argX_min=0
set argY_min=0
set a=0
:find_argX.min/argY.min
set /a a+=1
call set workingArgX=!argX%a%!
call set workingArgY=!argY%a%!
if %workingArgX% LSS %argX_min% set argX_min=%workingArgX%
if %workingArgY% LSS %argY_min% set argY_min=%workingArgY%
if not "%a%"=="%num_args%" goto :find_argX.min/argY.min
set workingArgX=
set workingArgY=
set a=


REM Create coordinate veriables
for /l %%D in (%argX_min%,1,%argX_max%) do (
for /l %%E in (%argY_min%,1,%argY_max%) do (
set cordx=%%D
set cordy=%%E
set "cord!cordx!.!cordy!=!space!"
)
)
set cordx=
set cordy=


REM assign 0
for /l %%A in (%argX_min%,1,%argX_max%) do (
for /l %%B in (%argY_min%,1,%argY_max%) do (
if %%A == 0 set "cord%%A.%%B=%zero%"
if %%B == 0 set "cord%%A.%%B=%zero%"
)
)


REM Assign arguments to coordinates
set a=-1
:cord.arg.loop
set /a a+=1
call set cord!arg%a%!=!cordinate!
if not "%a%"=="%num_args%" goto :cord.arg.loop
set a=

set /a y=%argY_max%+1
echo. >>tmp
:display_y.loop
set line=
set /a y-=1
set /a x=%argX_min%-1
:display_x.loop
set /a x+=1
set "line=%line%!cord%x%.%y%! "
if not "%x%"=="%argX_max%" goto :display_x.loop
echo %line% >>tmp
if not "%y%"=="%argY_min%" goto :display_y.loop

TYPE tmp
del /f tmp


REM Remove veriables from memory and exit
call :clearVar
goto :end


:Modifyers.start
set a=0
set b=0

if defined arg1 call :loop.findpoint

:check.loop
set /a a+=1

:: Help
if "!arg%a%!"=="/?" goto :help

:: Bug
if "!arg%a%!"=="-bug" goto :bug

:: ver
if "!arg%a%!"=="-ver" goto :ver

:: No arguments
if not defined arg%a% goto :help

:: Space Char
if "!arg%a%!"=="/s" set /a b=%a%+1
if "!arg%a%!"=="/s" set "space=!arg%b%!"
if "!arg%a%!"=="/s" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Coord Char
if "!arg%a%!"=="/c" set /a b=%a%+1
if "!arg%a%!"=="/c" set "cordinate=!arg%b%!"
if "!arg%a%!"=="/c" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Zero Char
if "!arg%a%!"=="/z" set /a b=%a%+1
if "!arg%a%!"=="/z" set "zero=!arg%b%!"
if "!arg%a%!"=="/z" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Line
if "!arg%a%!"=="/l" set /a b=%a%+1
if "!arg%a%!"=="/l" set /a c=%a%+2
if "!arg%a%!"=="/l" goto :graphLine "!arg%b%!" "!arg%c%!"

if not "%a%"=="%num_args%" goto :check.loop
set a=

goto :Modifyers.end

:loop.findPoint
for /f "tokens=1,2 delims==" %%A in ('set arg') do (
call :findpoint %%A %%B

)
goto :loop.findpoint.end

:findpoint
for /f "tokens=1,2 delims=." %%B in ("%2") do (
if not "%%C"=="" set arg_rep=%2
)
goto :eof

:loop.findpoint.end
goto :eof

:help
echo Graphs coordinates on a coordinate plane.
echo.
echo Graph ^[^[^/c ^<char^>^] ^[^/s ^<char^>^] ^[^/z ^<char^>^] x.y x.y x.y ...^]
echo ^[/l y=mx+b^] ^[^-bug^] ^[^/?^]
echo.
echo /c Defines what character the coordinates will be shown as.
echo /s Defines what character the empty spaces will be shown as.
echo /z Defines what character the axis will be shown as.
echo. /l Displays a line using y=mx+b input.
echo. /? Displays this help menu.
echo -bug Lists all KNOW bugs in the software.
echo -ver Lists current version.
echo.
echo.%%^^^&^)^=^|^;^"^<^>^,^^! Cannot be used with /c, /s or /z.
goto :end

:bug
echo.
echo Known bugs:
echo 1^) Modifyer /z does not work sometimes.
echo 2^) No current limit on hight of line graph.
echo 3^) Lines begin to wrap if points EXTEND too far in either direction.
goto :end

:graphLine
REM Grab Veriables
for /f "tokens=1,2 delims=x" %%B in ("!arg%c%!") do (
set slope=%%B
set yint=%%C
)

REM find point one
if "%yint%"=="" set "yint=+0"
if "%yint:~0,1%" == "+" set yint=%yint:~1%
set "points=0.%yint% "

REM find rise/run
for /f "tokens=1,2 delims=/" %%A in ("%slope%") do (
set rise=%%A
set run=%%B
)
if not defined rise set rise=1
if not defined run set run=1

REM find points +
set a=0
:loop.find_points_+
set /a a+=1
set /a working_run=%a%*%run%
set /a working_rise=%a%*%rise%+%yint%
set "points=%points%%working_run%.%working_rise% "
if not %a% EQU 4 goto :loop.find_points_+

REM find points -
set a=0
:loop.find_points_-
set /a a-=1
set /a working_run=%a%*%run%
set /a working_rise=%a%*%rise%+%yint%
set "points=%points%%working_run%.%working_rise% "
if not %a% EQU -4 goto :loop.find_points_-

REM assign arguments
set a=0
for %%A in (%points%) do (
set /a a+=1
set arg!a!=%%A
)
set num_args=%a%
goto :Modifyers.end

:clearVar
for /f "tokens=1 delims==" %%A in ('set ^| find "arg"') do set %%A=
for /f "tokens=1 delims==" %%A in ('set ^| find "cord"') do set %%A=
set zero=
set space=
set points=
set cordinate=
set rise=
set run=
set working_rise=
set working_run=
set yint=
set num_args=
set a=
set b=
set c=
set ver=
set error=
goto :eof

:ver
echo Version 3.5
goto :end

:end
exit /b
First verify this code fragment. Test your code in small chunks
Quote

@echo off
if "%1"=="-debug" (
shift
echo on
)
Add something to verify this part of the code is working. You code is too much. Batch code does not lend itself to easy testing, so you have to do bits and nibbles and have little FLAGS to tell what is going on. Why use echo off? Use echo on up until u got the code working. An annotate your code so other can help you.
Best I can do for you.I didn't SEE an issue with echo being turned off. See below (a.bat)

Code: [Select]d:\abc>a 1.2 3.4 6.8

0 - - - - - +
0 - - - - - -
0 - - - - - -
0 - - - - - -
0 - - + - - -
0 - - - - - -
0 + - - - - -
0 - - - - - -
0 0 0 0 0 0 0

d:\abc>123


Discussion

No Comment Found