Page 1 of 1

Variable Problems

Posted: 25 Sep 2010 22:19
by phillid
Hi. I have a program that you call like:

Code: Select all

output colours r g b y v


(The syntax is: output [profile] [output names])

It takes these arguments, and is supposed to put text up on the screen accordingly. There's a file called colours.ini that it looks in to know what to say. This looks like:

Code: Select all

[Text Configuration]
fc=0
bc=F
r=red
o=orange
y=yellow
g=green
b=blue
i=indigo
v=violet


Here's a draft of the code:

Code: Select all

@echo off
for /f "delims=" %%a in ('findstr /r /v /c:"^\[.*\]$" "%1.ini"') do set "%%a"
color %bc%%fc%
cls
shift
:loop
if defined %1 (
::DON'T KNOW WHAT TO PUT HERE!!!
::ECHO SOMETHING???
shift
goto loop
)


It needs to put the output in order of what's in the arguments etc, etc.
But my problem is this:
I don't know how to take %1, find the variable with a name that equals %1's content and echo that variable...

Hope it makes sense :wink:
Please Help!

Thanks,
phillid

Re: Variable Problems

Posted: 26 Sep 2010 02:26
by !k

Code: Select all

@echo off
setlocal enableextensions
for /f "delims=" %%a in ('findstr /r /v /c:"^\[.*\]$" "%1.ini"') do set "%%a"
color %bc%%fc%
cls
shift
for %%a in (%1 %2 %3 %4 %5) do call echo %%a = %%%%a%%
:?:

Re: Variable Problems

Posted: 26 Sep 2010 17:28
by phillid
Cool thanks! Just one thing: How could I get it so I could have an infinite number of arguments?

Thanks

Re: Variable Problems

Posted: 27 Sep 2010 07:32
by !k

Code: Select all

@echo off
setlocal enableextensions
for /f "delims=" %%a in ('findstr /r /v /c:"^\[.*\]$" "%1.ini"') do set "%%a"
color %bc%%fc%
cls
:loop
shift
for %%a in (%1) do call echo %%a = %%%%a%%
if not "%2"=="" goto :loop