Page 1 of 1

Problems with variables ...

Posted: 19 Nov 2018 15:29
by JamesJayceJohn
Hi
I have two files
The first is batch.ini and the second is batch.bat
I would like the string retrieved by the bat in the ini file display the variables defined in bat file.
With the following code, it does not work.
The string of characters retrieved does not display the variables defined in the bat file.
echo %csvchoice% --> %var1%;%var2%;%var3%
I am looking for the following result:
echo %csvchoice% --> James;Jayce;John

Thanks for your help

Batch.ini file:

Code: Select all

csvchoice=%var1%;%var2%;%var3%
Batch.bat file:

Code: Select all

set var1=James
set var2=Jayce
set var3=John

Define.Csvchoice.Ini

for /F "tokens=* delims= " %%f in ('findstr /R /C:"csvchoice=" batch.ini') do (
    
    
    set csvchoice_ini=%%f
    goto :End.Csvchoice.Ini
)

:End.Csvchoice.Ini


set csvchoice=%csvchoice_ini:~10%
echo Variable in batch.bat : %var1%;%var2%;%var3%
echo Variable in batch.ini : %csvchoice%

pause

Re: Problems with variables ...

Posted: 20 Nov 2018 10:57
by aGerman
Try

Code: Select all

call set "csvchoice_ini=%%f"
Steffen

Re: Problems with variables ...

Posted: 20 Nov 2018 12:22
by JamesJayceJohn
It's perfect !!

Thanks for this really quick help

Re: Problems with variables ...

Posted: 20 Nov 2018 13:50
by Squashman
If csvchoice is only present once in your INI file then there is no need for the GOTO command.

Re: Problems with variables ...

Posted: 21 Nov 2018 08:08
by Ed Dyreen
Squashman wrote:
20 Nov 2018 13:50
If csvchoice is only present once in your INI file then there is no need for the GOTO command.
And if unique identifiers are used then you can just

Code: Select all

<:unique_id <nul rem^ &for %%? in ( condition ) do if %%?==condition goto :unique_id
echo.previous loop aborted.
:End.Csvchoice.Ini, these are typically the types of labels I would never name with a unique identifier because the label does nothing more than abort a loop and is not used as the name of a function. If any label used at all I'd use one that is generic and implies it's purpose like :skip

Code: Select all

for %%? in ( condition ) do if %%?==condition goto :skip
:skip
echo.we skipped once

for %%? in ( condition ) do if %%?==condition goto :skip
:skip
echo.we skipped twice
you can have as many labels with the same name as you like, because goto doesn't jump upwards unless the end of file is reached which should be avoided in this case.