|
-
Mar 9th, 2011, 04:41 AM
#1
Thread Starter
Junior Member
[RESOLVED] Relative path isn't always recognized
Hi,
I have this problem since, like, forever, but now I decided to ask here and hopefully find a solution. When I open my project in VB and run it (debug), the app loads some images from external files which are in the same directory as the project. Usually, when I first open and run the project, everything works fine, but as soon as the second time (or third-it's pretty much random), an error 76 occurs saying "Path not found", but the path or file weren't modified. And this is also the case in all of my projects. If I close and re-open VB and run the project again, everything works fine again. I don't think this happens if I run the executable file of the app. I didn't use App.Path in paths, just the relative path.
Thanks
-
Mar 9th, 2011, 04:55 AM
#2
Re: Relative path isn't always recognized
Using relative paths (or no paths at all) means that you are relying on the "Current Working Directory" being the same as you intended, and staying that way too - and there are a variety of reasons that neither of those things are reliable.
In terms of the initial value, it can be changed by altering the shortcut to VB, or the shortcut to your compiled executable, or by running your compiled executable from a command line (from a different folder to where it is stored), and probably other things too.
In terms of the value changing, there are a variety of causes. One is for something in your program (including any references or components you use) to change it on purpose using ChDir or similar, and another is for certain situations with system based components (such as the common dialog) that cannot be entirely predicted as they behave differently on different versions of Windows.
If you want to refer to files that are in the same location as your executable, the way to do that reliably is to use App.Path
-
Mar 9th, 2011, 05:02 AM
#3
Thread Starter
Junior Member
Re: Relative path isn't always recognized
 Originally Posted by si_the_geek
Using relative paths (or no paths at all) means that you are relying on the "Current Working Directory" being the same as you intended, and staying that way too - and there are a variety of reasons that neither of those things are reliable.
In terms of the initial value, it can be changed by altering the shortcut to VB, or the shortcut to your compiled executable, or by running your compiled executable from a command line (from a different folder to where it is stored), and probably other things too.
In terms of the value changing, there are a variety of causes. One is for something in your program (including any references or components you use) to change it on purpose using ChDir or similar, and another is for certain situations with system based components (such as the common dialog) that cannot be entirely predicted as they behave differently on different versions of Windows.
If you want to refer to files that are in the same location as your executable, the way to do that reliably is to use App.Path
I see, thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|