Solved

Print a file to the temp directory

Posted on 2000-03-04
6
252 Views
Last Modified: 2010-05-02
I have a calculation program which writes a temp html document.  I want it to put it in the default temp directory regardless of which OS or computer it's running on.

Here's the problem I ran into.  I wrote the program on a computer with the temp directory in c:\windows\temp - when I ran the program at work it failed since the temp directory was c:\winnt\temp.


0
Comment
Question by:douglaskarr
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2583935
Dim sTempPath As String
sTempPath = Environ("TEMP")
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 10 total points
ID: 2583939
Or:

Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
    (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Command1_Click()
    Dim sTempPath As String
    Dim lRet As Long
    sTempPath = String(260, Chr(0))
    lRet = GetTempPath(Len(sTempPath), sTempPath)
    sTempPath = Left(sTempPath, lRet)
    Debug.Print sTempPath
End Sub
0
 
LVL 2

Expert Comment

by:repstein
ID: 2583951
The temp directory is specified as
ENVIRON("Temp")

As an example, the value in your user's case would be:
c:\winnt\temp

You can use this to build your string.

There are lots of other useful settings you can acces with environ.

To view them,

for i= 1 to 22
  debug.print environ(i)
next i


and look in the immediate debug window

Richard

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:repstein
ID: 2583954
Cross posted again &@*#(S(@!

But maybe you want to put the file in the TMP or USERPROFILE directory...
(Just use the namees listed in the debug.print output)

Richard
0
 
LVL 2

Expert Comment

by:repstein
ID: 2583955
Cross posted again &@*#(S(@!

But maybe you want to put the file in the TMP or USERPROFILE directory...
(Just use the namees listed in the debug.print output)

Richard
0
 

Author Comment

by:douglaskarr
ID: 2583957
Final Code:

Dim sTempPath As String
sTempPath = Environ("TEMP")

Open sTempPath & "\Answer.htm" For Output As #1
....

Worked Great!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Search combo error "Data Type Mismatch in Criteria Expression" 2 68
VBA Shell can't Find Word document 11 112
Spell Check in VB6 13 126
Dinamic report to Crosstab query 9 33
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question