Results 1 to 7 of 7

Thread: app.path

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    22

    app.path

    How does App.Path work? Any examples would help, I tried searching but found nothing helpful

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: app.path

    It returns the path where your project or exe is running at that time.

    casey.

  3. #3

  4. #4
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: app.path

    It comes in handy for getting files. If you stick your file in the same location as your project then you can easily access it.

    VB Code:
    1. sFileLocation = App.Path & "\File.txt"

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: app.path

    Quote Originally Posted by paralinx
    It comes in handy for getting files. If you stick your file in the same location as your project then you can easily access it.

    VB Code:
    1. sFileLocation = App.Path & "\File.txt"
    There is one gotcha if you do that.

    VB Code:
    1. If Right$(App.Path, 1) = "\" Then
    2.         sFileLocation = App.Path & "File.txt"
    3.     Else
    4.         sFileLocation = App.Path & "\File.txt"
    5.     End If

  6. #6
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: app.path

    Quote Originally Posted by paralinx
    It comes in handy for getting files. If you stick your file in the same location as your project then you can easily access it.

    VB Code:
    1. sFileLocation = App.Path & "\File.txt"
    Thats assuming your file isn't on the root of a drive, C: A:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim Ap As String
    4.  
    5. Sub Form_Load()
    6.  
    7. If Right$(App.Path, 1) = "\" Then
    8.     Ap = App.Path
    9. Else
    10.     Ap = App.Path & "\"
    11. End If
    12.  
    13. End If
    14.  
    15. Private Sub cmdSave_Click()
    16.  
    17. Open Ap & "Yourfile.txt" For OutPut As #1
    18. 'Save data
    19. Close #1
    20.  
    21. End If
    That way you don't have to think about the / if its needed or not. That way the exe can be anywhere you want it to be.
    Last edited by Keithuk; Jan 6th, 2006 at 07:52 PM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  7. #7

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    22

    Re: app.path

    Thanks I know what it is now :-)

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