Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory 2

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
What would I use to return the directory that my VB program's compiled exe resides in.

You see, I have a settings text file and I want my VB program to know where to look for it. It will be installed in the same directory as the exe file.

CurDir doesn't give me what I want.

Anyone help?

Thanks

elziko
 
This will give errors under certain circumstances.

If the end user of your application receives a CD to install the application, they may elect to install directly onto the C drive (only God knows why!!). In this case App.Path will return "C:\", so appending "\test.txt" will give the string "C:\\test.txt" = ERROR!!!!!

I usually create my own function (now stored in a general module which I include in all of my projects) like so:

Public Function App_Path() As String
If Right(App.Path, 1) <> &quot;\&quot; Then
App_Path = App.Path & &quot;\&quot;
Else
App_Path = App.Path
End If
End Function

Then, instead of appending &quot;\test.txt&quot;, or whatever the file is that you want, just append the file name to App_Path (App_Path will deal with the separator for you).

So, if you have a database, db1.mdb installed into the application folder, the full path and file name will be App_Path & &quot;db1.mdb&quot;, where ever the application is installed, whereas App.Path & &quot;\db1.mdb&quot; MAY give errors.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top