例: Environ 関数

次の例は Windows に特有の例です。Microsoft Windows 3.1 では、Temp 環境変数で定義されたディレクトリに一時ファイルが格納されます。次の例では、temp ディレクトリがカレントディレクトリになり、入力する文字列がそのディレクトリのファイル (MYAPP.TMP) に書き込まれます。temp ディレクトリの位置を決めるには、AUTOEXEC.BAT の Set Temp コマンドを調べてください。

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%