Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print a file to the temp directory

Posted on 2000-03-04
6
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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