• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

How can I create a flexible File path?

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
FantomPoet
Asked:
FantomPoet
1 Solution
 
CimperialiCommented:
'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
 
JonGartziaCommented:
Maybe you could store the installation path in the system registry. With GetSetting you could retrieve the path later.
0
 
rdrunnerCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
shijaz_aCommented:
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
 
FantomPoetAuthor Commented:
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
 
rdrunnerCommented:
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
 
CimperialiCommented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now