KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q43691: ENVIRON Sets Environment Variables Used by SHELL in QuickBASIC

Article: Q43691
Product(s): See article
Version(s): 4.00 4.00b 4.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | SR# S890421-61 B_BasicCom | mspl13_basic
Last Modified: 14-DEC-1989

The ENVIRON statement in BASIC can change the MS-DOS environment
variables to different values to be used by that program or a child
process invoked with the SHELL statement.

This information applies to Microsoft QuickBASIC Versions 4.00, 4.00b,
and 4.50 for MS-DOS, Microsoft BASIC Compiler Versions 6.00 and 6.00b
for MS-DOS and MS OS/2, and Microsoft BASIC PDS Version 7.00 for
MS-DOS and MS OS/2.

The ENVIRON statement allows you to alter the environment variables
for use by child processes started through BASIC. Once set, these
variables will remain set to the new values as long as you are in your
BASIC program or SHELL out to a child process.

BASIC makes a copy of the original DOS environment variables, and the
local copy can be changed with the ENVIRON statement. These changes to
the temporary copy of the DOS environment variables remain in effect
when BASIC SHELLs to another process.

When altering the environment table through BASIC, it is common for an
"OUT OF MEMORY" error message to be displayed. For more information on
the workaround for this error, query on the following keywords:

   ENVIRON$ Memory QuickBASIC

The following code example will print out the current copy of the
environment table, alter the PATH and PROMPT environment variables,
print out the environment table again, then SHELL and perform the DOS
SET command:

Code Example
------------

CLS
i = 1

DO WHILE ENVIRON$(i) <> ""   ' prints BASIC's environment table
    PRINT ENVIRON$(i)
    i = i + 1
LOOP

ENVIRON "PATH=;"              ' clear the PATH environment variable
ENVIRON "PATH=C:\DOS"         ' set the PATH environment variable
ENVIRON "PROMPT=;"            ' clear the PROMPT environment variable
ENVIRON "PROMPT=$P$G"         ' set the PROMPT environment variable

PRINT : PRINT

i = 1
DO WHILE ENVIRON$(i) <> ""    ' prints BASIC's environment table
    PRINT ENVIRON$(i)
    i + i + 1
LOOP

PRINT : PRINT
SHELL "set"   ' prints the environment table in BASIC's child process
END

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.