why does this give errors on some users, and works fine on others?
VB Code:
Open "C:\Windows\system32\newtext.txt" For Append As #1
Print #1, "test"
Close #1
If Not File_Exists(GetFile("test.txt")) Then
MkDir "C:\folder-test"
End If
Open GetFile("test.txt") For Append As #1
Print #1, "test2"
Close #1
Re: why does this give errors on some users, and works fine on others?
Re: why does this give errors on some users, and works fine on others?
it gives run time error 76 path not found on
Open "C:\Windows\system32\newtext.txt" For Append As #1
Print #1, "test"
Close #1
because after that it doesnt even make the new folder etc
Re: why does this give errors on some users, and works fine on others?
Are they using the same OS (XP)? You could use this API to find the current system folder. It could be on any drive letter.
VB Code:
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
'Show the windows directory
MsgBox "Windows System directory: " + sSave
End Sub
You didn't say where the error was, though.
Re: why does this give errors on some users, and works fine on others?
the person testing it is on windows 2000
everyone else who tested it is on xp and works fine for them
Re: why does this give errors on some users, and works fine on others?
Quote:
Originally Posted by Pouncer
it gives run time error 76 path not found on
Open "C:\Windows\system32\newtext.txt" For Append As #1
Print #1, "test"
Close #1
It seems that the file doesn't exist in the first place so it can't open it. Try checking if the file exists first, if it does then use the above code, if not then you'll need to create the file first
Re: why does this give errors on some users, and works fine on others?
What if their Windows isn't installed on C:\WINDOWS\?
What if their Windows isn't even on C:\?
What if they don't even have C:\?
Add these to a Module
VB Code:
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Function WinDir() As String
On Local Error Resume Next
Dim WindirS As String * 255
Dim temp As String
temp = GetWindowsDirectory(WindirS, 255)
WinDir = VBA.Left$(WindirS, temp)
End Function
Function SysDir() As String
On Local Error Resume Next
Dim WindirS As String * 255
Dim temp As String
temp = GetSystemDirectory(WindirS, 255)
SysDir = VBA.Left$(WindirS, temp)
End Function
Function TmpDir() As String 'Get temp dir
Dim WindirS As String * 255
Dim temp As String
temp = GetTempPath(255, WindirS)
TmpDir = VBA.Left$(WindirS, temp)
End Function
And to see what they return,
VB Code:
Private Sub Form_Load()
MsgBox WinDir
MsgBox SysDir
MsgBox TmpDir
End Sub
VB Code:
Dim i as Integer
i = FreeFile
Open SysDir & "\newtext.txt" For Append As #i
Print #i, "test"
Close #i
Re: why does this give errors on some users, and works fine on others?
That's what I thought. Windows 2000 lives in the old "\WinNT" folder. My previous post will resolve that.
Re: why does this give errors on some users, and works fine on others?
David, isn't in "WindowsNT" ?
AFAICR,
In WinNT, 2000 it is "WindowsNT"
and in Win95,98,Me,XP it is "Windows"
(Don't know anything about Win2003).
Re: why does this give errors on some users, and works fine on others?
Instead of using hard coded path use the %WINDIR% environmental variable.
Like,
also note that,
In Win95,98,Me the system directory is the "System" folder.
But in WinNT,2K,XP it is "System32" folder.
Edit: Use David's GetSystemDirectory method. It's easier and better.
Re: why does this give errors on some users, and works fine on others?
Windows NT 3.51, 4.0, 5.0 (2000) are all Winnt directories. Windows 95, 98, Me, XP are all Windows directories.
Re: why does this give errors on some users, and works fine on others?
Re: why does this give errors on some users, and works fine on others?
No prob. Thats why you need to use the APIs for dynamically obtaining the Windows (Winnt) directories using the GetWindowsDirectory API. ;)