?
Solved

How can I create a flexible File path?

Posted on 2003-03-13
7
Medium Priority
?
152 Views
Last Modified: 2010-05-01
Hi

I am currently opening a file for input as below:

Open "C:\Program Files\ESGHMI\Cam.bhf" For Input As #1

I now realise that during installation the user could select
an alternative path for the install, so affecting the ability for the
program to open files.

Is there a flexible way of giving a path? or alternatively a relative
way of accessing the file as oppossed to the absolute method above?

thanks for all you help

GAZ...
0
Comment
Question by:FantomPoet
[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
7 Comments
 
LVL 5

Accepted Solution

by:
Cimperiali earned 200 total points
ID: 8126800
'Some solutions may be:
'Use app.path - from where your app has been launching
dim thePath as string
thePath= app.path 'this is from where your app is running
if right(thepath,1)<>"\" then
   thePath=thePath & "\"
end if
'------------------------
'or: Ask the user!
dim thePath as string
thePath=inputbox("Disk\Folder to the file I need")
if dir(thepath,vbdirectory)="" then
   'not a valid path!
end if
'or: Search for it, starting from where it should be, then
'if not found, inform user and if it is ok for him, launch
'a recursive search through HD..
'---------------------------
'Or: mark your files as system/shared files during setup
'building: System will inform user not to move/delete
'them...
0
 
LVL 1

Expert Comment

by:JonGartzia
ID: 8126805
Maybe you could store the installation path in the system registry. With GetSetting you could retrieve the path later.
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 8126953
I would suggest to use

app.path

like Cimperiali already did. This will allow you to figure ot the folder at runtime. And if the user just moves the exe then he is stupid... (But SOME users will do that so get ready to catch the error)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:shijaz_a
ID: 8128043
As Cimperiali and rdrunner said use App.Path
For your example,

Open App.Path & "\Cam.bhf" For Input As #1

Please note that App.Path returns the path where the EXE was executed from. Even if the user moves the EXE file, it will report the current location of the EXE file from where it is running.

So, it will not cause an error as rdrunner said.
0
 

Author Comment

by:FantomPoet
ID: 8130068
Thanks for your advice guys.
This is my first time here and now I can't believe what a speedy resource I've come across.

THanks
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 8130200
I said it will cause an error since SOME USER will copy the EXE ONLY ;)

They will drag it onto their desktop and move the file there... Trust me they really do that ;)

If they copy the whole directory it wont cause an error ... but some ppl wont do that...

Sorry , but a few years at a help desk can make you really paranoid ;)

0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8134783
I agree with rdrunner: people will do that. Moreover, disks can have matters (such as bad clusters...). Thus remember to add Error Handling, and provide a way to let user search for missing files...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

770 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