Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done Just a Help addition - Set can indirectly set variables

Oct
364
17
No change to the code, but point out the following in the Help for Set:

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:

:: 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]​
 

Similar threads

Back
Top