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 this makes it much easier to carry on.
The Command Window is in fact a specialised instance of the Visual FoxPro editor. This
means that you can drag and drop between the Command Window and any code
windows. It allows you to test a snippet of code interactively before dragging it
into your program or to pull a line of code from a program and experiment with
it in the Command Window.
If you drag the Command Window to the bottom or to the side of the screen
then you can dock it so that it will never be covered by other FoxPro windows.
If you choose to leave the window floating on the screen then it may sometimes
disappear behind other wiondows. If this happens the shortcut is to press
to bring it to the front again. This key combination will
also open the window if you have closed it.
Entering, repeating and editing commands
The basic technique in the FoxPro Command Window is to type a command and press
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 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 that you've selected the correct set of records before you
actually delete them.
Start by typing something like:
browse for
country='USA'
This will show you 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
edit 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.xls
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 the same 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. FoxPro will execute the SQL directly
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 these four lines are really a single command.
Help
FoxPro follows the Windows convention so you can press
to open the Help system. You can also type help into the
Command Window. The is context sensitive and brings up help
on whatever it is that you are doing when you press the key. Typing
help displays the Help index but you can bypass this by adding the
name of a FoxPro command; help browse will display help on the
browse command.
Visual FoxPro is a self-contained language that is now separate from Visual Studio.
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 samples
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:
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 from the
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 with these you will find the application in the MSDN folder.
Introduction to Visual FoxPro |
Environment |
Project |
Tables |
Forms |
Navigation |
Executable
|