- Oct
- 364
- 17
No change to the code, but point out the following in the Help for Set:
Set can indirectly set variables:
Set can indirectly set variables:
UNSET Hello
Set var=Hello
:: Will echo Hello
Echo %var
Set %var=Goodbye
:: Will echo Hello
Echo %var
:: Will echo Goodbye
Echo %Hello
Here's a practical use example:Set var=Hello
:: Will echo Hello
Echo %var
Set %var=Goodbye
:: Will echo Hello
Echo %var
:: Will echo Goodbye
Echo %Hello
:: Just for demonstration
Unset MyFile Filename_var
GOSUB SELECT_FILE *.txt MyFile
:: Just for demonstration
Echo MyFile: %MyFile
Echo Filename_var: %Filename_var
quit
::******************************************************
:SELECT_FILE [Pattern Filename_var]
::
:: Gets filename
:: If no name is picked QUITS THE PROGRAM.
::
:: Parameters:
:: Pattern: pattern match for SELECT command
:: Filename_var: Holds the name of the VARIABLE
:: that the selected filename will be stored in
::
:: CALL WITH:
:: GOSUB SELECT_FILE Pattern MyFileVarName
::
::******************************************************
SELECT /1 SET tmp=(%Pattern)
:: No name picked (Esc pressed)
IFF "%tmp" EQ "" THEN
:: No file specified
ECHO.
ECHO NO FILE NAME SPECIFIED ! -- EXITING
PAUSE
QUIT
ENDIFF
Set %Filename_var=%tmp
UNSET tmp
RETURN
:: End of SELECT_FILE [Pattern Filename_var]
Unset MyFile Filename_var
GOSUB SELECT_FILE *.txt MyFile
:: Just for demonstration
Echo MyFile: %MyFile
Echo Filename_var: %Filename_var
quit
::******************************************************
:SELECT_FILE [Pattern Filename_var]
::
:: Gets filename
:: If no name is picked QUITS THE PROGRAM.
::
:: Parameters:
:: Pattern: pattern match for SELECT command
:: Filename_var: Holds the name of the VARIABLE
:: that the selected filename will be stored in
::
:: CALL WITH:
:: GOSUB SELECT_FILE Pattern MyFileVarName
::
::******************************************************
SELECT /1 SET tmp=(%Pattern)
:: No name picked (Esc pressed)
IFF "%tmp" EQ "" THEN
:: No file specified
ECHO.
ECHO NO FILE NAME SPECIFIED ! -- EXITING
PAUSE
QUIT
ENDIFF
Set %Filename_var=%tmp
UNSET tmp
RETURN
:: End of SELECT_FILE [Pattern Filename_var]