www.globabsystemsdesign.com

    Visual Basic Tips / Determining your application's startup path

Ok, you're writing an application which opens files which will be stored in your application's startup directory, but the users installing your program can put your program anywhere on their drives when they install it. So, how do you find out where they have put it when your program starts on their machine?

This is a pretty simple one. Visual Basic has a built in property of your application called Path.

Here is the result of using Debug.Print to get the startup path of a project of mine started from the Visual Basic IDE

Here's the call followed by the results.

    Debug.Print App.Path

    C:\VISUAL~1\PROJECTS\BIRTHDAY

Note that the path is returned in DOS style, the actual long file name version of the \Visual Basic folder is converted to read as it does above.

Here is some quick code which will check to see if a default file to load exists in your application's startup path.

    'assign full path and name of file to a variable
    FileToLoad = App.Path & "\" & "myfile.typ"
    ' check to see if myfile.typ file exists
    FileExists = Dir(FileToLoad)
    If FileExists <> "" Then
        'put the code to load your file here
    Else
        'put alternative code here for the case in which the file doesn't exist yet
    End If