Solved

Print a file to the temp directory

Posted on 2000-03-04
6
255 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 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

628 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