ENVIRON Statement Example See the ENVIRON statement programming example, which uses the ENVIRON$ function. ENVIRON Statement ---------------------------------------------------------------------------- Action Modifies or adds a parameter in the DOS or OS-2 environment-string table. Syntax ENVIRON stringexpression$ Remarks The argument stringexpression$ is a string constant or variable that contains the name of the environment variable, such as PATH or PROMPT. It can have the form parameterID= text, or parameterID text. Everything to the left of the equal sign or space is assumed to be a parameter, and everything to the right, text. The argument parameterID must contain all uppercase letters. For example. ----------------------------------------------------------------------------- This statement. Has this effect. ---------------------------------------------------------------------------- This statement. Has this effect. ---------------------------------------------------------------------------- ENVIRON "PATH=C.\SALES" Changes the path. ENVIRON "path=C.\SALES" Does not change the path. (It creates a new environment parameter not usable by the operating system.) If parameterID did not previously exist in the environment-string table, it is appended to the end of the table. If parameterID exists in the table when the ENVIRON statement is executed, it is deleted and the new parameterID value is appended to the end of the table. The text string is the new parameter text. If the 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. DOS or OS-2 discards the environment-string table modified by this function when your program ends. The environment-string table is then the same as it was before your program ran. Note You cannot increase the size of the environment-string table when using 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 variable(s). 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 process by creating a new environment variable. 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 usually is quite small. See Also ENVIRON$, SHELL Function Example The following example uses the ENVIRON$ function to get a copy of the current DOS path variable. The path variable is then changed using the ENVIRON statement. The contents of the environment-string table are then displayed using the ENVIRON$ function. DEFINT A-Z ' Initialize variables. Path$ = "PATH=" I% = 1 ' Store the old PATH. OldPath$ = ENVIRON$("PATH") ENVIRON "PATH=C.\BIN;C.\DOS;C.\BUSINESS\ACCOUNTING\RECEIVABLES\MAY" ' Display the entire environment-string table. PRINT "Your current environment settings are." PRINT DO WHILE ENVIRON$(I%) <> "" PRINT ENVIRON$(I%) I% = I% + 1 LOOP ' Change the PATH back to original. ENVIRON Path$ + OldPath$ ' Verify the change. PRINT PRINT "Your PATH has been restored to." PRINT PRINT ENVIRON$("PATH")