bas7ex.hlp (Topic list)
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 and ENVIRON$ Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the ENVIRON$ function to get a copy of your current
'PATH variable. Your PATH is then changed using the ENVIRON statement.
'The program then uses the ENVIRON$ function to print out the contents
'of the environment string table. The example concludes by restoring
'your original PATH statement.
 
'Note: For this example to run, the value of your path variable must be
'longer than the new path value in the ENVIRON statement.
 
DEFINT A-Z
'Initialize.
PATH$ = "PATH="
I% = 1
'Get the old PATH.
OldPath$ = ENVIRON$("PATH")
ENVIRON "PATH=C:\BIN;C:\DOS;C:\BUSINESS"
'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")