Variable Problems

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Variable Problems

#1 Post by phillid » 25 Sep 2010 22:19

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Variable Problems

#2 Post by !k » 26 Sep 2010 02:26

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%%
:?:

phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Re: Variable Problems

#3 Post by phillid » 26 Sep 2010 17:28

Cool thanks! Just one thing: How could I get it so I could have an infinite number of arguments?

Thanks

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Variable Problems

#4 Post by !k » 27 Sep 2010 07:32

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

Post Reply