The information in this article applies to:
SUMMARYMS-DOS versions 2.0 and later use an environment block. An environment block is a concatenated set of null-terminated (ASCIIZ) variable-length strings of the form: variable=valueThese strings provide information such as the following:
A local environment block is associated with each program in memory through a pointer contained at offset 2C hex in each program's PSP (program segment prefix). This article provides background information necessary when using the ENVIRON statement in Microsoft Visual Basic for MS-DOS, version 1.0; in Microsoft Quick Basic for MS-DOS, versions 4.0, 4.0b, and 4.5; in Microsoft Basic Compiler for MS-DOS, versions 6.0 and 6.0b; and in Microsoft Basic Professional Development System (PDS) for MS-DOS, versions 7.0 and 7.1. MORE INFORMATIONThe system's master environment block is normally owned by the shell COMMAND.COM. COMMAND.COM creates this set of environment strings in memory from the contents of the AUTOEXEC.BAT file, using the SET, PATH, and PROMPT commands. The initial size of COMMAND.COM's environment block can be controlled by loading COMMAND.COM with the /E parameter, using the SHELL directive in CONFIG.SYS. For example:
This line in CONFIG.SYS sets the initial size of COMMAND.COM's
environment to 2K. The maximum size the environment can be set to is
32K; the default size is 160 bytes. (The /P option prevents
COMMAND.COM from terminating, keeping it in memory until the system is
restarted.)
The SET command is used to display or change the COMMAND.COM environment contents. SET with no parameters displays the list of all the environment strings in the environment. A typical listing in the AUTOEXEC.BAT file might show the following settings:
The following is a dump of the environment segment containing the
previous environment example:
When a program is executed, such as when you start a .EXE, .COM, or
.BAT file by typing its name on the DOS command line, DOS sets aside a
256-byte block of memory for the program segment prefix (PSP). The PSP
contains various information that DOS uses to help run the program.
One part of this PSP contains the segment address of the local copy of
the master environment block.
Below is a diagram of the program segment prefix (PSP):
MS-DOS always builds a program's PSP in memory just below the memory area
allocated to the program itself.
(More detailed information on the PSP can be found in the "MS-DOS Encyclopedia" published by Microsoft Press.) If a transient program starts another transient program, then MS-DOS DOES NOT make a copy of the master environment table; MS-DOS makes a copy of the environment table of the parent program that made the call. Therefore, now there is a copy of a copy of the original table. When the child program started by the parent program terminates, any changes that were made to its local copy of the environment table are lost. Likewise, when the parent program terminates and control is returned to MS-DOS, its local copy of the master environment table is lost. Note that each copy of the environment table is exactly the size of the original, with no space for additions. Thus, if a program tries to add something to its environment table, an "Out of environment space" error message will occur. The environment table cannot get any larger that its original size. Therefore, before something can be added, one of the other variables must be deleted or reduced in size. The "Out of environment space" error can also occur if a TSR (Terminate-and-Stay-Resident) utility is installed when you try to add to the master environment table, or if adding to the master environment table exceeds the size specified in the CONFIG.SYS file with the /E parameter on the SHELL directive. The master environment table cannot be affected by any child program. For example, if you write a Basic program that alters the environment table using the ENVIRON statement, the local copy of the environment table is changed, not the original. To increase the size of the local environment block so that additional variables can be added, put a junk variable in the master environment block to hold space, and then erase it from the local copy to allocate space. For example, with a Visual Basic for MS-DOS program:
Remember that when this program terminates, the local environment table will be lost and it will be as if no changes were made to the environment. How to Make Basic Change Environment After ExitingTo make the Basic program change the MS-DOS environment after ending, you can perform the following steps using MS-DOS batch files:
REFERENCESThe information contained in this article was extracted from the following books from Microsoft Press: "The MS-DOS Encyclopedia" Additional query words: VBmsdos QuickBas BasicCom
Keywords : |
Last Reviewed: December 2, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |