Results 1 to 13 of 13

Thread: why does this give errors on some users, and works fine on others?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    why does this give errors on some users, and works fine on others?

    VB Code:
    1. Open "C:\Windows\system32\newtext.txt" For Append As #1
    2.                     Print #1, "test"
    3.                     Close #1
    4.            
    5.                     If Not File_Exists(GetFile("test.txt")) Then
    6.                         MkDir "C:\folder-test"
    7.                     End If
    8.                    
    9.                     Open GetFile("test.txt") For Append As #1
    10.                     Print #1, "test2"
    11.                     Close #1

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: why does this give errors on some users, and works fine on others?

    Which part doesn't work?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    4.  
    5. Private Sub Form_Load()
    6.     'KPD-Team 1998
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Dim sSave As String, Ret As Long
    10.     'Create a buffer
    11.     sSave = Space(255)
    12.     'Get the system directory
    13.     Ret = GetSystemDirectory(sSave, 255)
    14.     'Remove all unnecessary chr$(0)'s
    15.     sSave = Left$(sSave, Ret)
    16.     'Show the windows directory
    17.     MsgBox "Windows System directory: " + sSave
    18. End Sub

    You didn't say where the error was, though.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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

  6. #6
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    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

  7. #7
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    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:
    1. Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    2. Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    3. Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    4. Function WinDir() As String
    5.     On Local Error Resume Next
    6.     Dim WindirS As String * 255
    7.     Dim temp As String
    8.     temp = GetWindowsDirectory(WindirS, 255)
    9.     WinDir = VBA.Left$(WindirS, temp)
    10. End Function
    11. Function SysDir() As String
    12.     On Local Error Resume Next
    13.     Dim WindirS As String * 255
    14.     Dim temp As String
    15.     temp = GetSystemDirectory(WindirS, 255)
    16.     SysDir = VBA.Left$(WindirS, temp)
    17. End Function
    18. Function TmpDir() As String 'Get temp dir
    19.     Dim WindirS As String * 255
    20.     Dim temp As String
    21.     temp = GetTempPath(255, WindirS)
    22.     TmpDir = VBA.Left$(WindirS, temp)
    23. End Function
    And to see what they return,
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox WinDir
    3.     MsgBox SysDir
    4.     MsgBox TmpDir
    5. End Sub
    VB Code:
    1. Dim i as Integer
    2. i = FreeFile
    3. Open SysDir & "\newtext.txt" For Append As #i
    4.     Print #i, "test"
    5. Close #i

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  9. #9
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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).
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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,
    VB Code:
    1. Environ$("WINDIR")

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: why does this give errors on some users, and works fine on others?

    Thanks RD. Forgot it.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width