Examples: Environ function

The following example is specific to Windows. Microsoft Windows 3.1 stores temporary files in the directory defined by the Temp environment variable. This example makes the temp directory the current directory, and writes the string you enter to a file (MYAPP.TMP) in that directory. To determine the location of your temp directory, see the Set Temp command in your AUTOEXEC.BAT.

Dim TempDir As String, tempFile As Integer
Dim tempFileName As String, tempStuff As String
tempStuff$ = InputBox("Enter some temporary information")
TempDir$ = Environ("Temp")
ChDir TempDir$
tempFile% = FreeFile()
tempFileName$ = "myapp.tmp"
Open tempFileName$ For Output As tempFile%
Print #tempFile%, tempStuff$ 
Close tempFile%