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.

CREATE VIEW, SET VIEW, Set

Here’s a pair of commands you should avoid, plus one we use all the time. We can’t figure out why CREATE VIEW and SET VIEW aren’t marked “for backward compatibility only”—they should be. Actually, even in backward times, views of this sort weren’t such a good idea. SET by itself, though, is handy when you’re developing—it opens the Data Session (formerly known as View) window.

CREATE VIEW creates a “view file” with the extension VUE that contains information about the current FoxPro environment. SET VIEW reads the information in a VUE file and re-establishes that environment.

Usage

CREATE VIEW ViewFileName
SET VIEW TO ViewFileName | ?
SET VIEW ON | OFF
SET

Sounds pretty good, so what’s our complaint? First of all, views have never contained all the information needed to make them really useful. For example, they include the open tables and indexes, but not the record pointers for those tables. To really save the environment, try reduce, reuse, recycle.

Second and far more serious, VUE files (like MEM files) are a mysterious format. You can’t open them up and mess around, except using the Low-level File Functions. It makes far more sense to create your own status table—you can use the various status-tracking functions to get the information you need and store it all in a nice, readable format.

Don’t confuse this CREATE VIEW command with CREATE SQL VIEW, which lets you define views of remote and local data. Those views have nothing to do with these views.

The Help file lists all the things that get stored in a view, so we won’t repeat them here. We did find a couple of oddities in SET VIEW’s behavior, which we will share.

Although the current default directory is stored as part of the view, in VFP 3 it wasn’t restored. But the paths to open tables were stored relative to the default directory. So, if you SET VIEW from a different directory than you CREATEd it, VFP 3 couldn’t open the tables. VFP 5 and later versions are better behaved in this regard—they SET DEFAULT to the stored default directory.

In the “that’s interesting, but when will I ever use this?” category, Visual FoxPro’s updated View window (now called the Data Session window) tends to show open tables in reverse work area order. If you use the View window to open tables or you habitually issue SELECT 0 before USEing a table, you’ll normally see the tables in reverse work area order. When SET VIEW restores the open tables, they turn up in work area order in the View window. (We don’t know when you’ll ever use this piece of information, either.)

SET VIEW ON or OFF is something completely different. It controls the Data Session window. SET VIEW ON makes it appear, and SET VIEW OFF makes it disappear. We’ve never seen any reason to type that many characters, because using SET, by itself, opens the View window; pressing ESC while it has focus closes it.

See Also

AUsed(), Create SQL View, Relation(), Set, Set Alternate, Set Default, Set Fields, Set Filter, Set Format, Set Help, Set Path, Set Procedure, Set Resource, Set Skip, Set Status Bar, Used()