Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
ENVIRON Statement, ENVIRON$ Function Details
◄Summary► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
ENVIRON$ (env-variable$)
ENVIRON$ (n%)
ENVIRON stringexpression$
Usage Notes
■ The following example sets a PATH environment variable:
ENVIRON "PATH=C:\CLIENTS;C:\RATES"
■ If env-variable$ did not previously exist in the environment-string
table, it is appended to the end of the table. If env-variable$
exists in the table when the ENVIRON statement is executed, it is
deleted, and the new env-variable$ is appended to the end of the table.
■ If text is a null string ("") or a semicolon (";"), the existing
parameter is removed from the environment-string table, and the
remaining body of the table is compressed.
■ You cannot increase the size of the environment-string table with the
ENVIRON statement. This means that before you can add a new
environment variable or increase the size of an existing environment
variable, you must first delete or decrease the size of existing
environment variables.
■ Visual Basic generates the error message "Out of memory" when no more
space can be allocated to the environment-string table. The amount of
free space in the table is usually limited.
■ The environment variable must be expressed in all uppercase letters. For
example:
This Statement... Has This Effect...
═══════════════════════ ═══════════════════════════════════════
ENVIRON "PATH=C:SALES" Changes the path
ENVIRON "path=C:SALES" Does not change the path; creates a new
environment variable that cannot be used
by the operating system
■ MS-DOS discards the environment-string table modified by the ENVIRON$
function when your program ends. The environment-string table is then
the same as it was before your program ran.
■ You can use this statement to change the PATH parameter for a "child"
process (a program or command started by a SHELL statement) or to pass
parameters to a child by creating a new environment variable.
■ If you specify an environment-string name, but it cannot be found
in the environment-string table, or there is no text following it,
then ENVIRON$ returns a null string. Otherwise, ENVIRON$ returns
the text following the equal sign in the environment-string table.
■ If you specify a numeric argument (n), the nth string in the
environment-string table is returned. In this case, the string
includes all of the text, including environmentstring$. If the nth
string does not exist, ENVIRON$ returns a null string. The n argument
can be any numeric expression; it is rounded to an integer.