From: David on
NOTE: Questions follow ///////////////////////////////// separator

I'm using a routine from an MS Program.
The procedure does the following:

Open szFileName For Input As #1 'Open the next file to search.
strTempFile = GetTempPath() & "~~temp.sar"
Open strTempFile For Output As #2 'Open a temp file.

~~~~~~~~ Bunch Code ~~~~~~~~~

strTempFile nor #2 is referred to anywhere in this Bunch Code

~~~~~~~~~~~~~~~~~~~~~~~~~~~

Close #1
Close #2

Kill szFileName
FileCopy strTempFile, szFileName '<<File Must be closed to Copy

===== Supporting Procedure ============

Private Function GetTempPath() As String
'Find the path to the TEMP directory.
'Since we're only writing a few files,
'use "C:\" if there is no TEMP directory.
'This is kind of cheesy, could be done
'better.
'NOTE: There is also an API call of this same name
' Need to compare


'-----------------

Static szTempPath As String

If szTempPath = "" Then
szTempPath = Environ("TEMP")
If szTempPath = "" Then
szTempPath = "C:\"
ElseIf Right$(szTempPath, 1) <> "\" Then
szTempPath = szTempPath & "\"
End If
End If
GetTempPath = szTempPath

End Function

/////////////////////////////////////////////////////////////////////////////////

The program works great when run from the IDE.

When compiled strTempPath is blank when used with an Explorer
Right Click menu I created.

QUESTION
1) How can anything be in strTempPath to copy since nothing is
ever written to strTempPath in the Bunch Code area
-- yet everything works great in IDE?



From: David on
Please ignore the Post. -- Found IT!!!!



"David" <NoWhere(a)earthlink.net> wrote in message
news:%23RIoDBcNLHA.5984(a)TK2MSFTNGP06.phx.gbl...
> NOTE: Questions follow ///////////////////////////////// separator
>
> I'm using a routine from an MS Program.
> The procedure does the following:
>
> Open szFileName For Input As #1 'Open the next file to search.
> strTempFile = GetTempPath() & "~~temp.sar"
> Open strTempFile For Output As #2 'Open a temp file.
>
> ~~~~~~~~ Bunch Code ~~~~~~~~~
>
> strTempFile nor #2 is referred to anywhere in this Bunch Code
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Close #1
> Close #2
>
> Kill szFileName
> FileCopy strTempFile, szFileName '<<File Must be closed to Copy
>
> ===== Supporting Procedure ============
>
> Private Function GetTempPath() As String
> 'Find the path to the TEMP directory.
> 'Since we're only writing a few files,
> 'use "C:\" if there is no TEMP directory.
> 'This is kind of cheesy, could be done
> 'better.
> 'NOTE: There is also an API call of this same name
> ' Need to compare
>
>
> '-----------------
>
> Static szTempPath As String
>
> If szTempPath = "" Then
> szTempPath = Environ("TEMP")
> If szTempPath = "" Then
> szTempPath = "C:\"
> ElseIf Right$(szTempPath, 1) <> "\" Then
> szTempPath = szTempPath & "\"
> End If
> End If
> GetTempPath = szTempPath
>
> End Function
>
> /////////////////////////////////////////////////////////////////////////////////
>
> The program works great when run from the IDE.
>
> When compiled strTempPath is blank when used with an Explorer
> Right Click menu I created.
>
> QUESTION
> 1) How can anything be in strTempPath to copy since nothing is
> ever written to strTempPath in the Bunch Code area
> -- yet everything works great in IDE?
>
>
>


From: dpb on
David wrote:
> Please ignore the Post. -- Found IT!!!!
....

I surely would have hoped so...

--
From: Nobody on
"David" <NoWhere(a)earthlink.net> wrote in message
news:%231SpDJcNLHA.1996(a)TK2MSFTNGP06.phx.gbl...
> Please ignore the Post. -- Found IT!!!!

Glad that you found it, but there is another one hiding until it bites you
later. TEMP variable and even paths returned by GetTempPath() do not
necessarily exist, especially for a clean OS install or for a new user(Yes,
I get a tech support call about my software not working in a clean XP
install). Here is my code for getting the TEMP folder and create it if
needed:

' Form1 code:

Option Explicit

Private Sub Form_Load()
sTempDir = GetTempDir()
Debug.Print sTempDir
End Sub

' Module1 code:

Option Explicit

Public Const MAX_PATH As Long = 260
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" ( _
ByVal nSize As Long, ByVal lpBuffer As String) As Long

Public sTempDir As String

' Returns the Temp folder. Always ends with "\". Created if necessary.
Public Function GetTempDir() As String
Dim tmp As String
Dim TempPathLen As Long
Dim ResumeNext As Boolean
Dim ErrNumber As Long
On Error GoTo GetTempDir_Error

tmp = String(MAX_PATH, 0)
TempPathLen = GetTempPath(Len(tmp), tmp)
tmp = Left(tmp, TempPathLen)
If Not IsPathExist(tmp) Then
' Sometimes the folder does not exist
ResumeNext = True
MkDir tmp
ResumeNext = False
End If

If Right(tmp, 1) <> "\" Then
tmp = tmp & "\"
End If
GetTempDir = tmp

ExitSub:
Exit Function
GetTempDir_Error:
ErrNumber = Err.Number
If ResumeNext Then
Resume Next
Else
MsgBox "GetTempDir: Error " & ErrNumber & ": " & Err.Description
Resume ExitSub
End If
End Function

Public Function IsPathExist(Path As String) As Boolean
Dim ret As Long
Dim ResumeNext As Boolean
Dim ErrNumber As Long
On Error GoTo IsPathExist_Error

ResumeNext = True
ret = GetAttr(Path) And vbDirectory
ResumeNext = False
If ErrNumber = 0 Then
IsPathExist = True
End If

ExitSub:
Exit Function
IsPathExist_Error:
ErrNumber = Err.Number
If ResumeNext Then
Resume Next
Else
MsgBox "IsPathExist: Error " & ErrNumber & ": " & Err.Description
Resume ExitSub
End If
End Function