dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: File source locations

  1. #1
    Join Date
    May 2002
    Posts
    51

    File source locations

    Hi,
    How do I enter the source location for opening a text file, so that it can just be stored where the program is run from?
    for example:

    My current code is this,
    Open "c:\Coffee.txt" For Input As #ff
    the problem is, the file is not always going to be in the root c:, I want to locate it with the app, and be able to move the app to different directorys without reprogramming.

    Desired Code, something along the lines of,
    Open "(AppSource)\Coffee.txt" for input as #ff

    Many Thanks

  2. #2
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Code:
    Open App.Path & "\Coffee.txt" For Input As #ff
    Is all there is to it!
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  3. #3
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Code:
    MyPathFile = App.Path & "\MyFile.Txt"
    "App.Path" will always return the folder (location) of your running application.

    By the way, if you're using MS Access, there is no "App.Path" there. You can use this function:
    Code:
    Function AppPath() As String
      Dim ThisDBName  As String
      Dim I           As Integer
      Dim LenDBN      As Integer
      ThisDBName = Application.CurrentDb.NAME
      For I = Len(ThisDBName) To 1 Step -1
        If Mid(ThisDBName, I, 1) = "\" Then
          LenDBN = I - 1: Exit For
        End If
      Next
      AppPath = Left(ThisDBName, LenDBN)
    End Function
    Last edited by aio; August 20th, 2002 at 07:51 AM.
    Marketing our skills - please participate in the survey and share your insights
    -

  4. #4
    Join Date
    May 2002
    Posts
    51
    Thanks very much, I thought it would be something simple, but I didn't know the exact code.
    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)