VFP Tutorial - More about the environment

The FoxPro Command Window is something like the Immediate Window in a Microsoft Access database. The most obvious difference is that the results of your commands will appear on the FoxPro desktop rather than in the Command Window itself. The other difference is that the contents of the Command Window persist from one session to the next. It may seem a small point but when you fire up Fox on a Monday morning you can see what you were doing on Friday and it's easy to carry on.

The Command Window is a specialised instance of the FoxPro editor. This means that you can drag and drop between the Command Window and code windows. You can test a snippet of code interactively before dragging it into your program or pull a line of code from a program and experiment with it in the Command Window.

If you drag the Command Window to the side of the screen and dock it then it will never be covered by other FoxPro windows. If you choose to have the window floating on the screen then it may disappear. Press Ctrl+F2 to bring it to the fron again. This will also restore the window if you have accidentally closed it.

Entering and re-entering commands

The basic technique is to type a command in the Command Window and press Enter to execute it. You can re-execute any command by moving the cursor to any position in that line of the Command Window and pressing Enter again. You can also edit the existing line before executing it.

This is a reassuring feature when you are manipulating data from the Command Window. If for example you need to delete all the records of customers from the USA then you can approach the problem step by step and build confidence before you actually delete the records.

Start by typing something like:

browse for country='USA'

to see all the customers in the USA. If you are convinced that your selection is correct then you can take the cursor back up to that line and change the first word so that the command becomes:

delete for country='USA'

You have made no change to the selection criterion so you can be certain that you will be deleting the correct set of records. If you wanted even more reassurance, you could have edited the command to read:

copy to USAList type Xls for country='USA'

and exported a list of the records that are about to be deleted into an Excel spreadsheet. Many FoxPro commands share a similar syntax and you can save a lot of time and typing by just modifying earlier entries in the Command Window.

SQL

The example above used traditional dBase commands but Visual FoxPro also accepts SQL commands natively. You can type a command like:

select cust_id, company, country ;
   from customer ;
   where country='USA' ;
   into cursor csrUSA

into a program or into the Command Window and select the name and ID of all the USA customers into a temporary table. This SQL capability means that FoxPro databases can easily be upgraded to run on larger systems such as SQL Server, MySQL, or Oracle servers. SQL is also very useful for populating listboxes and combo boxes as a form loads.

Note that the semi-colons here are nothing to do with the syntax of SQL. The semi-colon is the FoxPro line-continuation character and indicates that this is really a single command.

Help

Press F1 or type help to open the Help system.

FoxPro is a self-contained language. Although it does integrate well with the rest of the Microsoft family you do not need to call on such things as ADO or Common Control DLLs or .Net in order to write a FoxPro system. The Help system is also self-contained and loads quickly because it is a single chm file.

FoxPro comes with a sample database of customers, invoices and stock tables in C:\Program Files\Microsoft Visual FoxPro 9\Samples\Data or in the equivalent folder on earlier versions of Visual FoxPro. This is only a small database with a few hundred records but it is a useful resource when you are learning. It is wise to copy the entire folder to your own folder before starting to use it so that you retain a clean copy of the original data.

Another useful resource supplied with Visual FoxPro is the Solutions application:

[Solutions Application in Visual FoxPro]

The Solutions application consists of perhaps a hundred small forms and programs which demonstrate useful techniques. These are supplied with their complete source code and a dedicated help file to explain the techniques that have been used. Select Do from the Program menu then navigate to the C:\Program Files\Microsoft Visual FoxPro 9\Samples\Solution folder and run Solutions.App.

Early versions of Visual FoxPro shipped as part of the Visual Studio suite and have the application in the MSDN folder.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

Access Tips

FoxPro Tips

General Tips

 

Related Items

Visual FoxPro Tutorial - Program control

Program control structures in Visual FOxPro

Read More

Visual FoxPro Tutorial - Do Case

Visual FoxPro Tutorial - Using the Do Case structure to control program execution

Read More

Visual FoxPro Tutorial - Program Code

Visual FoxPro Tutorial - Writing program code

Read More

Visual FoxPro Tutorial - Development Environment

The Integrated Development Environment (IDE) for Visual FoxPro

Read More

Visual FoxPro Tutorial - Build an executable

Visual FoxPro Tutorial - Build a Windows executable from a Foxpro project

Read More