Chapter 1: Introduction to Programming In Visual FoxPro, procedural and object-oriented programming work together so you can create powerful, flexible applications. Conceptually, you can think of programming as writing a sequence of instructions for accomplishing specific tasks. At a structural level, programming in Visual FoxPro involves manipulating stored data. If you are new to programming, this chapter helps you get started. For an explanation of object-oriented programming, see Chapter 3, Object-Oriented Programming.
|Published (Last):||5 November 2004|
|PDF File Size:||1.5 Mb|
|ePub File Size:||14.8 Mb|
|Price:||Free* [*Free Regsitration Required]|
Chapter 1: Introduction to Programming In Visual FoxPro, procedural and object-oriented programming work together so you can create powerful, flexible applications. Conceptually, you can think of programming as writing a sequence of instructions for accomplishing specific tasks. At a structural level, programming in Visual FoxPro involves manipulating stored data. If you are new to programming, this chapter helps you get started.
For an explanation of object-oriented programming, see Chapter 3, Object-Oriented Programming. Advantages of Programming Generally, anything that you can do in a program can also be done manually if you have enough time. For example, if you wanted to look at information about a single customer in a table of customers, say the Ernst Handel company, you could do it manually by following a specific sequence of instructions.
To manually find a single order in a table 1. From the File menu, choose Open. From the Files of type box, choose Table. Double-click Customer. From the View menu, choose Browse. Scroll through the table, checking the Company field of the records for Ernst Handel. To manually increase the maximum order amount 1. Suppose, however, that you wanted to increase the maximum order amount of every customer by 3 percent.
To do this manually would be laborious and prone to mistakes. If you give the right instructions in a program file, Visual FoxPro can accomplish this task quickly and easily, without error. The semicolon ; indicates that the command is continued on the next line. End of the code that is executed for every record in the table. Running a program has some advantages over entering individual commands in the Command window: G Programs can be modified and run again.
G You can run programs from your menus, forms, and toolbars. G Programs can run other programs. The following sections detail the mechanics, concepts, and processes behind this and other Visual FoxPro programs. You can include these instructions in: G The Command window. You can even run multiple lines of code from the Command window as though they were a self-contained program.
To run multiple lines of code in the Command window 1. Select the lines of code. Since the Command window is an editing window, you can edit commands using the editing tools available in Visual FoxPro. You can edit, insert, delete, cut, copy, or paste text in the Command window. The advantage of entering code in the Command window is that the instructions are carried out immediately.
There is no need to save a file and run it as a program. In addition, choices you make from menus and dialog boxes are echoed in the Command window as commands. You can copy and paste these commands into a Visual FoxPro program, then run the program repeatedly, making it easy to execute thousands of commands again and again.
You can create a program in Visual FoxPro in one of these ways: To create a program 1. In the Project Manager, select Programs under the Code tab. Choose New. From the File menu, choose New. In the New dialog box, select Program. Choose New File. Saving Programs After you create a program, be sure to save it. To save a program G From the File menu, choose Save.
If you try to close an unsaved program, a dialog box opens, prompting you to either save or discard the changes you made to it. If you save a program that was created from the Project Manager, the program is added to the project. If you save a program that hasnt been named yet, the Save As dialog box opens so you can specify a name for the program. After you save your program, you can run or modify it. Modifying Programs After you save your program, you can modify it.
First, open the program in one of these ways: To open a program G If the program is contained in a project, select it in the Project Manager and choose Modify. A dialog box with a list of available files appears. From the Files of type list, choose Program. From the list of files, select the program you want to modify, then choose Open. After you open the program, you can make changes. When you finish making your changes, be sure to save the program. Running Programs After you create a program, you can run it.
To run a program G If the program is contained in a project, select it in the Project Manager and choose Run. From the list of programs, select the program to run, then choose Do. The Report Designer allows you to create complex and customizable reports by integrating code into the report file. To take advantage of the full power of Visual FoxPro, you need to use these design tools.
Basic Programming Concepts When you program, you store data and manipulate it with a series of instructions. The data and data storage containers are the raw materials of programming. The tools you use to manipulate this raw material are commands, functions, and operators. Storing Data The data you work with probably includes amounts of time, money and countable items, as well as dates, names, descriptions, and so on. Each piece of data is a certain type: it belongs to a category of data that you manipulate in similar ways.
You could work directly with this data without storing it, but you would lose most of the flexibility and power of Visual FoxPro. Visual FoxPro provides numerous storage containers to extend your ability to easily manipulate data. Data types determine how data is stored and how it can be used. You can multiply two numbers together, but you cant multiply characters. You can print characters in uppercase, but you cant print numbers in uppercase.
Data Containers Data containers allow you to perform the same operations on multiple pieces of data. For example, you add the hours an employee has worked, multiply them by the hourly wage, and then deduct the taxes to determine the amount of pay the employee has earned.
Youll have to perform these operations for every employee and every pay period. If you store this information in containers, and perform the operations on the containers, you can just replace the old data with new data and run the same program again.
Multiple rows of predetermined fields, each of which can contain a predefined piece of data. Tables are saved to disk. Multiple elements of data stored in RAM.
Manipulating Data Containers and data types give you the building blocks you need to manipulate data. The final pieces are operators, functions, and commands. Using Operators Operators tie data together. Here are the most common operators in Visual FoxPro.
Result Prints. Prints 25 Prints 5. Note A question mark? Remember that you must use the same type of data with any one operator. The following statements store two numeric pieces of data to two variables. The variables have been given names that start with n so we can tell at a glance that they contain numeric data, but you could name them with any combination of alphanumeric characters and underscores.
The variables have been given names that start with c to indicate that they contain character data. For example, STR returns the character equivalent of a numeric value and VAL returns the numeric equivalent of a character string of numbers. These functions and LTRIM , which removes leading spaces, enable you to perform the following operations:?
For example, the functions STR and VAL , used in the previous section, return character and numeric values, respectively. As with all functions, these return types are documented along with the functions. There are five ways to call a Visual FoxPro function: G Assign the return value of the function to a variable. The following line of code prints the current system time in the active output window:? TIME Call the function without storing the return value anywhere. The following function call turns the cursor.
The following line of code prints the day of the week:? Returns the name of a field. Returns the number of characters in a character expression. Returns the number of records in the currently active table. Returns the specified number of characters from a character string, starting at a specified location in the string.
Using Commands A command causes a certain action to be performed.
Visual Foxpro 6 Programmer's Guide
Visual FoxPro is an object-oriented programming language, as well as a development environment, application platform, and database engine. It started life as FoxBASE in , and had what was — at that time — the fastest database management system available. This was a derivative of the dBase systems designed in the late s. At that point was FoxPro was a programming language with built-in database system. Fox Technologies, the company that created FoxPro, merged with Microsoft in In , Visual FoxPro 3.
Learn Visual Foxpro @ garfieldhudson.com
Foxpro was created in early 80's originally as FoxBase - ? It was known as the fastest database engine on PCs then. Later on , unfortunately , it was acquired by Microsoft. At the end of , Foxpro got the name "Visual" and the platform support was only limited to windows. It was also the first version of Foxpro where the language turned out to be Object Oriented.
Special Edition Using Visual FoxPro 6
Learn Visual Foxpro garfieldhudson. Free tables are not associated with a database container. Modification involves adding or removing columns or changing existing column types. It focuses on standard programming concepts and constructs e. This is the first of a series of videos on programming VFP Forms. Video Length: View Download Data Buffering This video picks up from the last Forms video and shows how to implement data buffering very quickly.