Results 1 to 5 of 5

Thread: Use file without specifying hole path

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    18

    Use file without specifying hole path

    If I dont know the hole path og the file, but knows that it is in the same directory as the program, how do I refer to it, because I can't just say:
    Open "File.txt" For Random As #1
    as would be natural.
    -Nack

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    app.path will return your program's location.
    Please rate my post.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    open app.path & "\file.txt"
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    18
    Thanks!

  5. #5
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Usually you wont run into this problem but you should test for it anyway.

    App.path returns a slash at the end when you are in the Root directory (ex: C:\) but it does not if you are not in the root (ex: C:\temp)

    Therefore you should always use this code to make sure its done properly. Add it to a module or the form code.

    VB Code:
    1. public function getFilePath(strPath as String, strFileName as String) as String
    2.     if Right(strPath, 1) <> "\" then
    3.         getFilePath = strPath & "\" & strFileName
    4.     else
    5.         getFilePath = strPath & strFileName
    6.     end if
    7. end Function

    Then call it like this
    VB Code:
    1. Dim strFilePath as String
    2. strFilePath = GetFilePath(app.path, "myfilename.txt")
    3. open strFilePath for input as #1 'or whatever u want to do with it
    4. 'etc etc

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