Look at the case of VFP: Output query results as a table or a text file

Source: Internet
Author: User

Looking at the example of VFP: Summarize the results of the query in this example, the summary results are displayed in the table control. This article makes further improvements to this example, and you can select Datasheet or text file at run time to output the results of the query as "query results" while displaying the summary results in the table control. DBF "or" query result. txt ".

This example applies the knowledge of the GROUP BY clause in the SELECT statement, and for the SELECT statement, refer to the Select SQL command or the SQL language tutorial. This example applies to the Data environment and uses the "People Information table" in the "Data 1" database as the data source for the data environment, and the situation of the database is already looking at the case study VFP: sample database is given in the article, the running interface is shown at the end of this article.

Production steps:

A new form, set its Caption property value to "Output query results as a table or text file," and the AutoCenter property value set to the. T.,width property value is set to the 375,height property value set to 275, and the form is saved as " Output the query results as a table or text file. Scx ".

Add a Label control, a combo box control, and a command button control to the form, line the three controls, and set their properties individually:

1. Label control: The Caption property value is set to rollup criteria.

2, combo box control Combo1:rowsourcetype property value set to "N-value", RowSource property value set to "department, gender, education."

3. The command button control command1:caption the property value to total.

Third, at the bottom of this line of the Totals button, add a Label control and set its Caption property value to output format. Add an Option button Group control (OptionGroup) to the right of the label control, right-click the added option button Group control Optiongroup1, and select the Edit command when a blue-green dotted line appears around the control (this is the editing state for the option button group. In this state, you can modify the properties of individual option buttons within an option button group control, drag Option1 and Option2 to arrange them horizontally in the option button group control, and then click to select Option1 and Option2, and then set their caption properties to "datasheet" in turn and "text files," as shown in the following illustration:

Right-click the blank space of the form, select the Data Environment command, and add the people information table to the data environment. In the Data Environment Designer, drag the title bar of the People information table onto the form to automatically generate a table control. Since the "People information table" is dragged from the data environment and is automatically generated by the system, the RecordSource property and RecordSourceType properties of the table control are set by the system, and we modify the Name property value of the table control to "GRID1".

To adjust the position of each control on the form, the Adjusted form Designer is shown in the following illustration:

Vi. Add event code:

(i) The Init event for the form:

Public SC
sc= ' into table query result '

(ii) The Click event Command1 the summary button:

If used (' Query results ') Sele query results use endif private CXTJ,TJ cxtj=thisform.combo1.displayvalue if Empty (CXTJ) && judgment column Whether the table boxes and text boxes are empty messagebox (' Please enter the full condition! ', 16, ' system hint ') Thisform.combo1.setfocus else does case alltrim (CXTJ) = ' Department ' tj= ' department, Count (number) as number, Su
	M (basic salary) as total wage;
	AVG (basic salary) as average wage, count (number)/reccount () *100 as Percent ' case alltrim (CXTJ) = ' sex ' tj= ' sex, COUNT (number) as number, sum (basic salary) as total wage; AVG (basic salary) as average wage, count (number)/reccount () *100 as Percent ' case alltrim (CXTJ) = ' education ' tj= ' degree as education, count (number) as number, count (number)/ RecCount () *100 as% ' endcase if sc= ' into table query result ' Select &TJ.
	From Personnel information table; Group by &CXTJ.
      &sc. else Select &TJ.
	From Personnel information table; Group by &CXTJ. into cursor query results Select &TJ.
	From Personnel information table; Group by &CXTJ.
      &sc. endif thisform. Grid1.columncount=-1 thisform.grid1.refresh thisform.grid1.recordsource= ' query results ' thisform.grid1.backcolor= RGB (200,224,248) Thisform.refresh endif cLear return 

Run "Output the query results as a table or text file. Scx", the interface is shown in the following figure:

Resources:

The basic course of VFP: http://bianceng.cnhttp://www.bianceng.cn/vfpjc/index0.htm

VFP Primary Course: http://bianceng.cnhttp://www.bianceng.cn/cc/index.htm

VFP Intermediate Course: http://bianceng.cnhttp://www.bianceng.cn/mcc/mcc.htm

VFP Advanced Course: http://bianceng.cnhttp://www.bianceng.cn/hcc/hcc.htm

VFP Network Development: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpwlkf.htm

VFP Call API function: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpapi.htm

VFP Report Print: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpreport.htm

VFP Common technique: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpcyjs.htm

VFP Experience Summary: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpjyhz.htm

VFP Control use: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpkjsy.htm

VFP Data processing: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpsjcl.htm

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.