Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Creating Reports with Visual FoxPro

computers


Creating Reports with Visual FoxPro

McAlister Merchant

Microsoft Corporation

Created: April 2001

Revised: April 2001

Applies To: Microsoft Visual FoxPro

Summary

This paper shows how to create Visual FoxPro reports and discusses issues to consider beyond direct data access, issues related to the needs for reports, and issues related to planning and creating online and offline reports. You can use the Report wizard to quickly get a report of any single or related tables. If you want to customize your report, or add non-data elements, use the Report designer.



Contents

What is Data?

Planning a Report

Creating a Single-table Report

Creating a Multi-table Report

Introduction

Although Microsoft Visual FoxPro data can be reported to the screen simply as a Browse window or a form, properly designed reports lend clarity, readability 414v216e , and distributability to data that turns it from developer data to user information. Reports are great for display and distribution of the information available from data, because they are easily repeated, duplicated, and shared.

It is easy to build simple reports in Visual FoxPro. Indeed, the very tools you use to create tables provide ways to immediately see all the data available (for more information, see the "Creating Tables with Visual FoxPro" paper in MSDN Online).

The Report designer or Report wizard are helpful especially if you want to create a report that displays in one view the relationships or the combined information between two or more tables. This paper uses the Report wizard to create two reports - a simple single-table report and a multiple-table report.

What is Data?

Visual FoxPro deals with data in tables. Data is discrete and can be found in an ever-expanding range of types. Visual FoxPro can access most of it, but access is often not enough. To use data effectively, you must turn it into information - you must report it. This is not always a magical process. Usability can be as simple as a little pre-planning. Effectiveness can take more effort. Typically, you spend more time using or designing reports then you spend creating tables.

Planning a Report

With reports, not only is planning important, but it is recurrent and, sometimes, recursive. Use a report when you want to get the same information repeatedly or when you want to encourage specific activity or aid particular processes.

An effective report is one that makes it possible for you to use information quickly, whether you use all the available data or not. The way to start report planning is to think about how that report will be used.

Often, information is more inspiring or thought provoking when it is formatted properly or organized carefully. For example, if you are preparing for a staff meeting, it might be helpful to create reports in which data is organized by staff responsibilities, as well as by time, geographic, or financial relationships. If it is your address book or contacts list, you might find it helpful to create one or more reports organized by zip code (state), or birth month, phone area code, or hobby.

When you gather information for records in an address book or contact list, you enter all the information about one individual; however, you might create each record at different times and places. Even if you create several records at one time, you still complete one record before you begin the next. Several records can have identical values, but without a report it can be difficult to know which ones or how many. It can be important and useful to have a way to see these and other relationships.

Online or Printed Reports

If you are going to display data online or in print, there are some issues you should consider:

Scrolling   If your information cannot be displayed in one screen page, then consider separate pages rather than a long scroll. In addition, consider a different visual organization of the data, such as labels, positioning, or the use of white space.

Labels   This influences both the eye (where users look for information) and the mind (what users expect to find).

Spacing and Positioning   This can be as important as font size for focus and clarity.

White space   Most people do not enjoy reading large blocks of text online, so good use of white space can make your report more effective.

Location   This is as important in screen real estate as it is in land. The top, the center, the right, and then the left are most often the important screen areas.

If your report can access background information or relevant data directly rather than always display it, then the basic report is more effective (and you have more room for the most important information).

Creating a Single-table Report

If you only want to look at what you have, use the Browse window on any table.

To access the Browse window

In the File menu, open the table.

From the View menu, select Browse.

If you want to print or mail a report quickly, you can export the file as text, and then print or mail the new text file. The Export dialog box options make it possible for you to select portions of the table to convert to text. (Remember to check the paper orientation for wide tables.)

To report raw data from a table as text quickly

From the File menu, select Open.

In the Open dialog box, select Table in the Files of type drop-down list, locate the table you want, and click OK.

From the View menu, select Browse.

This displays the selected table. At this time, in the IDE, you can change the column widths or locations, or you can make lasting changes from the Table menu.

From the File menu, select Export.

In the Export dialog box, select Delimited Text from the Type drop-down list.

If you were going to use the table in another application, such as Microsoft Excel, you could select the application from the list, and the table would be converted to the proper format and saved with the correct extension.

Click the To button, and specify the file name of your new file. Include the extension.

In the Field separator drop-down list, select the delimiter you want in the new file, and then click OK.

Visual FoxPro Report Wizard

If you find you must have formal presentations, summaries, or calculations, or you must use the same information repeatedly, then use the Report wizard or the Report designer to generate reusable, updateable, modifiable reports.

The Report wizard prompts you with choices that make it possible for you to create a well-formatted report of one or more tables quickly. In many circumstances, these quick reports work very well.

To use the Report wizard

From the File menu, choose New, and then select Report.

In the New dialog box, click Wizard, and select the type of report you want to create.

In the wizard, you can preview a report before you save it. In addition, you can save it and then open it in the Report designer to use the Visual FoxPro IDE to add to your report design.

To experiment with the Report wizard, use the Labels.dbf table, which ships with Visual FoxPro. Use the following procedures to work with simple, one-table reports

To create a simple Report using the Labels.dbf table

In the File menu, click New.

In the New dialog box, select Report and click the Wizard button.

In the Wizard selection dialog, double-click Report Wizard.

In the Report wizard, select Free Tables in the Databases and Tables drop-down list, and select or locate the Labels table.

Select any or all the available fields, and continue the wizard. Continue the wizard and make the appropriate selections up to Step 5.

In Step 5, choose a report style and orientation.

In addition, you can click Summary options to access five functions - Sum, Avg, Count, Min, and Max - for fields displayed in your report. The selected functions are added automatically with appropriate labeling and positioning.

In Step 6, click the Preview button to see the report your selections would create if you click Finish. You can print the preview without creating a report file.

The Report wizard creates labels and selects fonts, font sizes, indentation, and other styling and formatting characteristics to help turn the table data into report information. Often, creating reports with the wizard is as fast as creating the ad hoc Browse window copy, and it is much prettier.

Click Finish.

For more information on the Report wizard, see "Report Wizard" and "One-To-Many Report Wizard" in the Visual FoxPro Help.

Visual FoxPro Report Designer

You can use the Report designer to create simple reports, called Quick Reports. In addition, the Report designer is a powerful tool for creating formatted reports. The main difference between using the Report wizard and using the Report designer is that the designer provides greater control of the positioning of data and other content.

To create Quick Reports with the Report designer

In the File menu, click New.

In the New dialog box, select Report, and click the New File button.

In the Report menu, select Quick Report.

If you have a table open, Visual FoxPro will use it as the source for your report. If no table is open, Visual FoxPro displays the Open dialog box, so you can choose a table.

The Report designer populates the Detail and Page Footer bands. Then, the details are up to you. You have more control than with the Report wizard; you also have more responsibility. If you want to generate information, such as sums, averages, or counts, use Data Grouping on the Report menu. Your specification for a data group can be as simple as the name of the index field selected from the Expression builder.

To create a report containing a calculation

To perform this operation, open an ordered table (indexed on cust_id), create a Quick Report as basis, specify data grouping, and then specify how and where in the report the calculation is displayed. The final steps are to preview, print, and save the report.

From the File menu, open the ..\samples\DATA\orders.dbf table.

From the Window menu, open the Data Session dialog box, and click the Properties button for the orders table.

In the Work Area Properties dialog box, choose Orders.cust_id as the Index order, click OK, and then close the Data Session dialog box.

Open the Report Designer. In the File menu, select the New option. From the New dialog box, select Report, and then click New File.

From the Report menu, select Quick Report, and then select the vertical layout.

Note   For this example, you do not need all the fields, so you might want to remove the labels and fields following order_amt, as well as the labels and fields between emp_id and order_date. Move the fields together, and resize the report bands.

In the Report menu, choose Data Grouping.

In the Data Grouping dialog box, click the Ellipsis button (...) under Group Expressions. In the Fields list in the Expression builder, double-click Orders.cust_id. Click OK in both dialog boxes.

In the Report Designer, place a copy of the order_amt field in the Group Footer band for group totals, and place another copy in the Page Footer for the entire table.

Copy, paste, and then drag the copied fields from the Detail band.

For each copy of order_amt, double-click the field to open the Report Expression dialog box.

Click the Calculations button.

Select the Sum function from the Option Group.

The Reset drop-down list should display the default selection, which is the Order.cust_id field. This means that the Sum function resets to zero each time the value of the cust_id field changes in the pass through the table. This is fine for the group sub totals, but you must change this selection for the order_amt field in the Page Footer band.

After you select Sum in the Calculate Field dialog box of the order_amt field you placed in the Page Footer band, change the Reset value to End of Report.

After setting the Calculation field of each order_amt, close the dialog boxes by clicking OK.

Use the print preview to see what you have created and to make sure that you are getting the information you expected. Save the report if you are satisfied with it. The last page displays the total for all orders - information not specifically included in the table.

While the Report designer is open, you have access to tools and other designers, so you can review the current table or modify the data environment by selecting other tables or indexes. In addition, you can add frills and functionality to the report through the Report Controls toolbar and the Report menu.

For more information on the Report designer, see the "Report Designer" and "Report Designer Band Dialog Boxes" topics in the Visual FoxPro Help.

Creating a Multi-table Report

In addition to single-table data, Visual FoxPro reports can display data from several related tables and can perform calculations and produce summaries.

This procedure uses two tables, customer and orders, from the testdata.dbc database in the Samples folder.

To create a report using the Testdata database that ships with Visual FoxPro

In the File menu, click New.

In the New dialog box, select Report, and click the Wizard button.

In the Wizard selection dialog box, double-click One-To-Many Report Wizard.

In the One-To-Many Report wizard, select the TESTDATA database in the Databases and Tables drop-down list, and select the Customer table.

In Step 1 of the wizard, highlight the Customer table, and select the cust_id and Customer fields from the Available Fields drop-down list.

In Step 2, highlight the Orders table, and select the cust_id, to_city, and order_amt fields from the Available Fields drop-down list.

In Step 3, you see the way the two tables are related - customer.cust_id to orders.cust_id; in other words, the tables are indexed on matching fields.

If you want a different relationship, you could choose from the drop-down lists for the parent and child tables. If you change the specified relationship, you would also have to make sure you had chosen the correct fields in steps 1 and 2.

In Step 5, choose a report style and orientation.

In addition, you can click Summary options to access five functions - SUM, AVG, COUNT, MIN, and MAX - for fields displayed in your report. The selected functions are added automatically with appropriate labeling and positioning.

In Step 6, click the Preview button to see the report your selections would create if you click Finish. You can print the preview without creating a report file.

Click Finish.

You can create the same report in the Report designer, but to specify the database and the tables, you must establish the data environment of the report. You then use that data environment in a Quick Report or through drag-and-drop in the IDE to create your report.

For samples of various kinds of report you can create, see the Solutions sample application in the Visual FoxPro Help.

For more information on using reports, see "Using Expressions and Functions in Field Control in a Report" in the Visual FoxPro Help.

Text for description meta tag: Visual FoxPro provides wizards, designers, and commands to create data reports quickly and easily.

Keywords: Visual FoxPro Reports, creating; Visual FoxPro, creating reports; Visual FoxPro, viewing reports; Visual FoxPro, editing reports; Visual FoxPro, Report wizard; Visual FoxPro, Report designer; report wizard; report designer


Document Info


Accesari: 3035
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )