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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Location of Project

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
106
PH
Hi!

I'm creating a simple program with menu that will run a specific form when selected.
When I select from my submenu I get a Program error of location does not exist. The location of pjx and dbf files are located in different folders. I had to set my Default Directory to the project folder because it's not running.

001_or0kcm.jpg


002_ilyfq4.jpg


code - pjx,scx,prg,mpr files
data - dbf files
etc - images


I found out that my error is from the Default Directory that sets on the code folder instead of data.

Below is my mainutil.prg
Code:
Close All 
Set Default To Sys(2019,1) 

DO proc_sets 

Public empidvar,deptidvar,formvar,clonevar,lognamevar,deptcodevar 
empidvar=0 
deptcodevar = 0 
formvar="" 
clonevar=0 
lognamevar="" 

_Screen.Hide 
Do Form intro.scx 
Read Events

How can I set my location without setting the Default Directory?

Thank you [smile]
 
SYS(2019,1) is the file name including the path to an external config file (typically config,fpw).
This also means it's empty if the EXE (or the IDE) doesn't use a config file.

If you do, this determines the default and you can start your EXE with the command line switch -C to any config file in the path you want to make your default. That also has the nice touch to it you can make a few settings depending on the config file directory if that matters. Not as versatile as an INI, but better than nothing.

I personally wouldn't use anything that has a prerequisite I don't want to be forced to use. I usually compile a config.fpw into the EXE and disallow external config.fpw files, but if you want the user of your EXE to have that control, allow it.

An EXE will start with the directory given in a shortcut to start the EXE, too, so there is an alternative chance to allow external influence without using any SET DEFAULT, if you want that.

If you want something else perhaps first remove that line. You can use a combination of _vfp.startmode to decide between design/runtime, then SYS(16), _vfp.fullname, _vfp.servername. Win API may have some more functions giving you paths, like standard system paths. You could strip off the dependency of code running only when the right default directory is set by using SET PATH with m multiple paths VFP will then search (with some ambiguity problems, when several files in the paths have the same name, obviously). And then you can use any means of your own configuration files, from INI over XML or dbf configuration data to registry settings.

Pick your poison.

Bye, Olaf.

Olaf Doschke Software Engineering
 
If I've understood your question correctly, you only need to identify your data directory at run time. The location of your project is immaterial at run time.

If you want to use the default directory to store your data, then you need to execute [tt]SET DEFAULT TO <data directory>
[/tt]. You can either hard-code the name of the data directory, or you can retrieve it from somewhere, such as an INI file, a custom config file, or the Windows Registry.

That said, it is more usual to store the data in a specific directory other than the default. If you never create new tables at run time, then you can use [tt]SET PATH[/tt] to specify the data directory. That way, your program will always be able to find your data files. If you do need to create new tables at run time, you will need to specify their path in the command that creates them, for example [tt]CREATE TABLE <name and path of table>[/tt].

Apologies if I've misunderstood your requirements.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you for the replies.

I just stick to SET DEFAULT TO for all of my forms. [peace]

And it works just fine.
 
Nobody said you can't use SET DEFAULT. Obviously you can change the directory (SET DEFAULT does the same as CD) at any point in an application you want to. I just pointed out alternatives of SYS(2019) to determine an important path.

I don't think I tell you anything new, but when you don't want to change the [tt]Set Default To Sys(2019,1)[/tt] then it will only move you to the right directory, if the config.fpw is in the right directory AND the EXE also uses it. It's only automatic, if the config.fpw is in the same directory and named exactly that, otherwise use the -C switch I mentioned. If this should always be the EXE directory SYS(16) is the winner, it doesn't depend on anything but the EXE path, you just need to be cautious within the IDE where it points to, but no problem, when all your code files are in just one directory.

If this isn't working just look into what SYS(2019,1) is giving you at runtime. If it's nothing (empty) you don't control your default directory with this, if it's an unexpected path check where that comes from. Or use something else pointing at the forms directory.

Bye, Olaf.



Olaf Doschke Software Engineering
 
I think I overlooked something, and sorry for that, let me go back to your explicit question:
TheLazyPig said:
How can I set my location without setting the Default Directory?
You can't, Well, you can CD or CHDIR, but that is effectively the same.

I know why SYS(2019,1) won't work. It's not a path, it's a fully pathed file name. So take the path part of it:
Code:
SET DEFAULT TO JUSTPATH(SYS(2019,1))

SYS(16) would also require you to use JUSTPATH(), that was quite automatic to me and I didn't realize SYS(2019,1) would actually give you the file name and not just the path, as I assumed you used that code for a long time already and it stopped working. You just had the idea this would be the easiest thing to determine "here". I don't know why people are allergic to SYS(16).

So there you have your fix if you still want to make use of that, just stay alert about anyone messing with your default directory by using the -C command option when running your EXE. You can't prevent that when you want to orient yourself with the path to that file. There is the ALLOWEXTERNAL=NO option, but that only makes sense in a config file you include in compilation.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top