|
-
Jan 7th, 2006, 10:17 PM
#1
Thread Starter
Frenzied Member
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
-
Jan 7th, 2006, 10:20 PM
#2
Re: why does this give errors on some users, and works fine on others?
-
Jan 7th, 2006, 10:21 PM
#3
Thread Starter
Frenzied Member
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
-
Jan 7th, 2006, 10:22 PM
#4
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.
-
Jan 7th, 2006, 10:24 PM
#5
Thread Starter
Frenzied Member
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
-
Jan 7th, 2006, 10:26 PM
#6
Re: why does this give errors on some users, and works fine on others?
 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
-
Jan 7th, 2006, 10:34 PM
#7
Hyperactive Member
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
-
Jan 7th, 2006, 10:37 PM
#8
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.
-
Jan 7th, 2006, 10:51 PM
#9
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).
-
Jan 7th, 2006, 10:56 PM
#10
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.
Last edited by iPrank; Jan 7th, 2006 at 11:05 PM.
-
Jan 7th, 2006, 11:00 PM
#11
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 11:02 PM
#12
Re: why does this give errors on some users, and works fine on others?
Thanks RD. Forgot it.
-
Jan 7th, 2006, 11:06 PM
#13
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|