Results 1 to 2 of 2

Thread: Open file

  1. #1
    Join Date
    Nov 2004

    Unanswered: Open file


    If I use "open filename for input as 1", what is the default directory where VB looks for?

    Can this default directory be changed?

    I would like to have this directory be the same as the directory where the .vbp file (or .exe after compilation) is.



  2. #2
    Join Date
    Jun 2004
    Arizona, USA
    Open uses the application's working directory. Normally, this is the location of the executable. If you're running in the IDE, this is normally the project folder.

    Normally, you just include the full path name as a part of the file name. However, your example above is misleading. It SHOULD say

    Open PathName For Input as #1

    Or, use the ChDrive and ChDir statements to change the application's default directory.

    Finally, the VB6 App object is very useful. One of it's properties, (Path) is often used.

    Open App.Path & "\" & "FileName" For Input as #1

    for instance. Be aware, however, that App.Path has one bug. IF your current directory is the root folder on a disk drive, app.path returns the trailing backslash. If you are in a different folder, it does NOT return the trailing backslash. (I believe this was reversed on Windows versions prior to Win XP)

    A useful workaround is as follows:
    Public Function AppPath () as String
      Dim strPath as String
      strPath = App.Path
      If Right$(strPath,1) <> "\" Then
        strPath = strPath & "\"
      End If
      AppPath = strPath
    End Function
    Use it just as you would the App.Path property.
    Last edited by loquin; 07-03-08 at 16:10.
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Posting Permissions

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