1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Just a Help addition - Set can indirectly set variables

Discussion in 'Suggestions' started by Rick Reinckens, Nov 28, 2014.

  1. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    96
    Likes Received:
    4
    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]​
     

Share This Page