1.

Solve : Remove veriable?

Answer»

So I am creating a batch file that will create a graph of points input as arguments. The issue arose when I try to add a feature to change the display characters. For some reason, when I go to remove the verable, it doesn't work for some, but works the rest of the time.
Code: [Select]C:\Users\Lemonilla\Documents\prog\bat\table>graph 1.2 4.6 6.7 9.3
the program STORES arguments as %arg%
so if we use 'set a' we get a list of the argument veriables * removed stuff standard stuff
Code: [Select]arg1=1.2
arg2=4.6
arg3=6.7
arg4=9.3

The code: (error near the bottom in :modifyers)
Code: [Select]@echo off
setlocal EnableDelayedExpansion
set cordinate=+
set space=-

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=

call :Modifyers
set >log
notepad log

set a=0
:find_argX/argY
set /a a+=1
for /f "tokens=1,2 delims=." %%B in ('call echo !arg%a%!') do (
set argX%a%=%%B
set argY%a%=%%C
)
if not "%num_args%"=="%a%" goto :find_argX/argY



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=



for /l %%D in (1,1,%argX_max%) do (
for /l %%E in (1,1,%argY_max%) do (
set cordx=%%D
set cordy=%%E
set "cord!cordx!.!cordy!=!space!"
)
)
set cordx=
set cordy=



set a=0
: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
:display_y.loop
echo.
set /a y-=1
set x=0
:display_x.loop
set /a x+=1
0>nul set /p"=!cord%x%.%y%!"
if not "%x%"=="%argX_max%" goto :display_x.loop
if not "%y%"=="0" goto :display_y.loop
set y=
set x=



for /f "tokens=1 delims==" %%Y in ('set a ^| find "arg"') do (
set %%Y=
)
for /f "tokens=1 delims==" %%Z in ('set c ^| find "cord"') do (
set %%Z=
)
set space=

exit /b


:Modifyers
set a=0
:check.loop
set /a a+=1
:: Space Char
if "!arg%a%!"=="/s" set /a b=%a%+1
if "!arg%a%!"=="/s" call set "space=!arg%b%!"
if "!arg%a%!"=="/s" set arg%a%=
if "!arg%a%!"=="/s" set arg%b%=
:: Coord Char
if "!arg%a%!"=="/c" set /a b=%a%+1
if "!arg%a%!"=="/c" call set "cordinate=!arg%b%!"
if "!arg%a%!"=="/c" set arg%a%=
if "!arg%a%!"=="/c" set arg%b%=
if not "%a%"=="%num_args%" goto :check.loop
goto :eof

The problem is that it will sometimes not remove the values of /c or /s, CAUSING the program to error when it tries to check 'if /c GTR 0'


'set a' (from 'graph /c 0 /s + 1.2 2.3 4.5 6.7')
Code: [Select]arg2=0
arg4=+
arg5=1.2
arg6=2.3
arg7=4.5
arg8=6.7

EDIT: the other issue that could be happening is that %b% is not being assigned the correct value. Don't know why this would happen though.Found the issue, needed to flip which one got reset. Because arg%a% was getting reset before arg%b%, the if statement was returning false.

finished code (fixed another bug before posting)
Code: [Select]@echo off
setlocal EnableDelayedExpansion
set cordinate=+
set space=-

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=

call :Modifyers

set a=0
:find_argX/argY
set /a a+=1
for /f "tokens=1,2 delims=." %%B in ('call echo !arg%a%!') do (
set argX%a%=%%B
set argY%a%=%%C
)
if not "%num_args%"=="%a%" goto :find_argX/argY



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=



for /l %%D in (1,1,%argX_max%) do (
for /l %%E in (1,1,%argY_max%) do (
set cordx=%%D
set cordy=%%E
set "cord!cordx!.!cordy!=!space!"
)
)
set cordx=
set cordy=



set a=0
: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
:display_y.loop
echo.
set /a y-=1
set x=0
:display_x.loop
set /a x+=1
0>nul set /p"=!cord%x%.%y%!"
if not "%x%"=="%argX_max%" goto :display_x.loop
if not "%y%"=="0" goto :display_y.loop
set y=
set x=



for /f "tokens=1 delims==" %%Y in ('set a ^| find "arg"') do (
set %%Y=
)
for /f "tokens=1 delims==" %%Z in ('set c ^| find "cord"') do (
set %%Z=
)
set space=



echo.
exit /b



:Modifyers
set a=0
set b=0
:check.loop
set /a a+=1
:: Space Char
if "!arg%a%!"=="/s" set /a b=%a%+1
if "!arg%a%!"=="/s" call set "space=!arg%b%!"
if "!arg%a%!"=="/s" set arg%b%=0.0
if "!arg%a%!"=="/s" set arg%a%=0.0
set b=0
:: Coord Char
if "!arg%a%!"=="/c" set /a b=%a%+1
if "!arg%a%!"=="/c" call set "cordinate=!arg%b%!"
if "!arg%a%!"=="/c" set arg%b%=0.0
if "!arg%a%!"=="/c" set arg%a%=0.0
set b=0
if not "%a%"=="%num_args%" goto :check.loop
set a=
goto :eof
Lemonilla,
Interesting CHALLENGE for a batch file.

I gave your script a test and ended with these results.
-Screen Shot-
Quote

F:\test_it>graph 1.2 4.6 6.7 9.3
-----+---
---+-----
---------
---------
--------+
+--------
---------
F:\test_it>
Are the results what I should expect from the script?
Thank you!if we check the point (1,2) we know that it will be 1 to the right (on the x axis) and 2 up (on the Y axis). If the bottom left point is (1,1) then we count up one to get to (1,2) and find the point (represented by a "+").

checking the next point: (4,6) we would count right 3, and up 5 (because the bottom right is (1,1) ) we get the 2nd highest point.

From what I'm seeing, they all seem to work.


EDIT: also if you change line
Code: [Select]0>nul set /p"=!cord%x%.%y%!"
to
Code: [Select]0>nul set /p"=!cord%x%.%y%! "
(found under the flag :display_y.loop, 3rd block from the bottom.)
(added a space before the 2nd quotation mark)
You will get a much nicer looking graph, as it appears to be more to scale

Code: [Select]
C:\Users\Lemonilla\Documents\prog\bat\table>graph 1.2 4.6 6.7 9.3

- - - - - + - - -
- - - + - - - - -
- - - - - - - - -
- - - - - - - - -
- - - - - - - - +
+ - - - - - - - -
- - - - - - - - -

C:\Users\Lemonilla\Documents\prog\bat\table>
Correct me if I am wrong but most X,Y graphs I have seen all start at ZERO.The 9,3 plotting point looks weird/wrong.fixed to start on (0,0)
Code: [Select]@echo off
setlocal EnableDelayedExpansion


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


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
:find_argX/argY
set /a a+=1
for /f "tokens=1,2 delims=." %%B in ('call echo !arg%a%!') do (
set argX%a%=%%B
set argY%a%=%%C
)
if not "%num_args%"=="%a%" goto :find_argX/argY


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 Create coordinate veriables
for /l %%D in (0,1,%argX_max%) do (
for /l %%E in (0,1,%argY_max%) do (
set cordx=%%D
set cordy=%%E
set "cord!cordx!.!cordy!=!space!"
)
)
set cordx=
set cordy=


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=


REM Display table
set /a y=%argY_max%+1
:display_y.loop
echo.
set /a y-=1
set x=-1
:display_x.loop
set /a x+=1
0>nul set /p"=!cord%x%.%y%! "
if not "%x%"=="%argX_max%" goto :display_x.loop
if not "%y%"=="-1" goto :display_y.loop
set y=
set x=


REM Remove veriables from memory and exit
for /f "tokens=1 delims==" %%Y in ('set a ^| find "arg"') do (
set %%Y=
)
for /f "tokens=1 delims==" %%Z in ('set c ^| find "cord"') do (
set %%Z=
)
set space=
goto :end


:Modifyers.start
set a=0
set b=0
:check.loop
set /a a+=1
:: Space Char
if "!arg%a%!"=="/s" set /a b=%a%+1
if "!arg%a%!"=="/s" call set "space=!arg%b%!"
if "!arg%a%!"=="/s" set arg%b%=0.0
if "!arg%a%!"=="/s" set arg%a%=0.0
set b=0
:: Coord Char
if "!arg%a%!"=="/c" set /a b=%a%+1
if "!arg%a%!"=="/c" call set "cordinate=!arg%b%!"
if "!arg%a%!"=="/c" set arg%b%=0.0
if "!arg%a%!"=="/c" set arg%a%=0.0
set b=0
:: Help
if "!arg%a%!"=="/?" (
echo Graphs coordinates on a coordinate plane.
echo.
echo Graph ^[^/c ^<char^>^] ^[^/s ^<char^>^] x.y x.y x.y ...
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.
echo %%^^^&^)^=^|^;^"^<^>^,^! Cannot be used with /c or /s.
goto :end
)
:: No arguments
if not defined arg!a! echo The syntax of the command is incorrect.
if not defined arg!a! goto :end
if not "%a%"=="%num_args%" goto :check.loop
set a=
goto :Modifyers.end

:end
Code: [Select]7 - - - - - + - - -
6 - - - + - - - - -
5 - - - - - - - - -
4 - - - - - - - - -
3 - - - - - - - - +
2 + - - - - - - - -
1 - - - - - - - - -
0 1 2 3 4 5 6 7 8 9

Will work on MAKING the numbering automaticWhat if I want to input 0.5?Code: [Select]
C:\Users\Lemonilla\Documents\prog\bat\table>graph 0.5

+
-
-
-
-
-

C:\Users\Lemonilla\Documents\prog\bat\table>graph 0.5 6.9

- - - - - - +
- - - - - - -
- - - - - - -
- - - - - - -
+ - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -

C:\Users\Lemonilla\Documents\prog\bat\table>

Though if you enter in a negative value, you get a blank Y axis.Lemon, You seem to be using y,x plotting points instead of the x,y notation. Is there a reason for that?Code: [Select]C:\Users\Lemonilla\Documents\prog\bat\table>graph 0.5 6.9
Y
9 - - - - - - +
8 - - - - - - -
7 - - - - - - -
6 - - - - - - -
5 + - - - - - -
4 - - - - - - -
3 - - - - - - -
2 - - - - - - -
1 - - - - - - -
0 - - - - - - -
0 1 2 3 4 5 6 X

No, I am using (x,y). (0,5) would be right 0 on the X and up 5 on the Y.

http://nces.ed.gov/nceskids/createagraph/default.aspx?ID=5e30cb9e4c5248e1a899869b2c1b16f8BTW ...it's variable.


Discussion

No Comment Found