Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Add

This method of the Files collection lets you add files to a project.

Usage

oAddedFile = oFiles.Add( cFileName )

Although Add adds to a project, it’s actually a method of the Files collection of the project, not of the project itself. The corresponding Remove method belongs to the File object rather than the Files collection. It makes sense in terms of what they do, but it is a little confusing at first glance.

You pass Add the name of the file you want to add, and it puts that file in the project. Then, it returns an object reference to the file object created, so that you can continue to manipulate it.

You have to include the extension as part of the filename, since you can add all kinds of files to a project. In fact, if you add a file with an extension that VFP doesn’t recognize as a project component, it puts it into “Other Files” rather than choking. Nice job. If you add a table that’s bound into a database, the whole database is added to the project.

If the file isn’t in the current directory, you need to include the path to it (even if it’s in the current SET PATH list).

In tools, you’re probably better off using the Files collection of the project than depending on the reference returned by Add, although everything seemed to behave as long as we didn’t get too tricky.

Example

MODI PROJ MyProject
oProj = Application.ActiveProject
oProj.Files.Add("MyNewProg.PRG")

See Also

File, Files, Name, Project, Remove