Solved

Get current path

Posted on 2001-08-22
12
270 Views
Last Modified: 2009-07-29
How can I get the path that my program is running from upon running my program?
0
Comment
Question by:Barb0400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +3
12 Comments
 
LVL 3

Expert Comment

by:SirNick
ID: 6413876
Try

form1.caption =form1.path
0
 
LVL 3

Expert Comment

by:SirNick
ID: 6413890
Of course you will have to probably compile your program first.
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 20 total points
ID: 6413900
Text1.text = app.path
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6413909
Vinny is correct  :)
0
 
LVL 3

Expert Comment

by:SirNick
ID: 6413961
Yes I agree with Dave_Greene that Vinny is right, I have just tried out my suggestion and I now realise that there is no 'path' property for form1.

Sorry
0
 

Expert Comment

by:Arvindtn
ID: 6414354
Use this win32 API to get the current directory

Public Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Hope this solves ur problem.

0
 

Expert Comment

by:peterchamberlin
ID: 6414392
What I do is to declare a global AppPath variable and then use the following code right near the program start...

AppPath = App.Path
If Right$(AppPath,1)="\" Then
   AppPath = Left$(AppPath,Len(AppPath)-1)
End IF

The reason for this being that if your program is running from root directory, such as C:\, then normal app.path returns "C:" only and so will muck up any usage of AppPath and backslashes in the rest of your program.

You can get the current operational directory using CurDir(), and change this if necessary with ChDir to your path.

For references to files etc. always use AppPath & "\FileName.ext" or AppPath & "\Directory\FileName.ext"
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6414429
Peter, you have been around this forum long enough to know that you shouldn't be proposing answers to questions... especially when your suggestion has already been commented in this thread.  Barb, please reject Peters proposed answer.

Dave
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6414473
The only other thing I would add is to keep in mind that App.Path == CurDir at the startup of your application if you run it by double clicking on the EXE file in a Windows Explorer or if started by a shortcut that has same directory in the Start In field of the properties page.  Otherwise they will be different based on the value of the Start In field.  The CurDir will be the path in that field or the directory that the shortcut is stored in if left blank.

Regards,

eeevans
0
 

Expert Comment

by:peterchamberlin
ID: 6414487
"you shouldn't be proposing answers to questions"

Well, sorry, I'll refrain from posting anything in future !

App.Path had been commented on, but not the problem with the backslash, neither had CurDir been mentioned.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6414516
Peter I'm not trying to brow beat you into not posting comments.  Please do!!!  but when you post your comment as "THE ANSWER", it moves the question to the locked area, where it gets less visibility, and is basically a dis-service to the question asker.  

No hard feelings my friend!

-Dave
0
 

Expert Comment

by:peterchamberlin
ID: 6414864
Apologise, I wasn't aware of the loss of visibility to a question's status on providing a possible answer. Will leave such as comments in future.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question