ENVIRON$ function


Retrieve information from the current program's environment table.


s$ = ENVIRON$({parameter_string | n})


parameter_string is a string expression denoting which environment parameter is to be retrieved.  n is an integer-class expression, starting at 1.

If a string argument is used, ENVIRON$ returns the text that follows parameter_string (after the equal sign) in the environment table.  If parameter_string is not found, or no text follows the equal sign in the environment string table, an empty string is returned.

If the numeric argument is used, it acts as an index into the environment table.  ENVIRON$ returns a string containing the nth parameter from the start of the table.  If there is no nth parameter, an empty string is returned.  If the index is negative, private Windows variables are returned.

When launching a program from within the IDE, PowerBASIC sets the "PBIDE" environment variable with the IDE name and version number.  For example, "CCEDIT 5.00" or "PBEDIT 9.00".  Similarly, when running in the debugger, the "PBDEBUG" environment string will return the IDE name and version.

Programs can use these environment strings to detect their "mode" of operation, for example, to signal a program to save internal data to a disk file, and when to display helpful debugging information.  DLLs created with PB/Win can also examine these environment strings and adapt behavior accordingly.  This will be of particular interest to 3rd-party DLL programmers who create libraries and add-ons for other PowerBASIC programmers.


When a program (process) starts, it is given its own local environment table, which is typically a copy of the parent program's environment table.  ENVIRON$ works with this local table, not the parent's table.

See also



' Retrieve the PATH environment variable

Path$ = ENVIRON$("PATH")



  CALL DisplayMyDebugData()


' Enumerate all Environment strings



  INCR x&

  a$ = ENVIRON$(x&)

  ' process a$ here