Solved

Print a file to the temp directory

Posted on 2000-03-04
6
249 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now