Look at the case of VFP: Statistical calculation of the results of the query

Source: Internet
Author: User
Tags exit

This example to look at the case of VFP: more complex Query the article has made further improvements, in meeting the query function, but also the results of the query can be counted. This example also applies to the data environment, and using the "People Information table" in the data 1 database as the data source of the data environment, the situation of the database is already looking at the case of VFP: sample database is given in the article, run the interface see the end of this article.

The production steps are as follows:

First, create a new form, set its Caption property value to "count the query results", and set the AutoCenter property value to. T.,width property value set to 520,height property value set to 295 and saved as "Statistical calculation of query results. Scx".

Second, right click the blank space of the form, select the Data Environment command, 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 by the system, the RecordSource properties and RecordSourceType properties of the table control have been set by the system, and for the convenience of writing code, we modify the Name property value of this table control to " Grid1 ".

Third, add a Label control below the table control and set its Caption property value to query criteria.

On the right side of the label control, add two combo box controls, a text box control, and two command buttons Command1 and Command2, set the Caption property values of the two command buttons to statistics and exit, and line the controls into one row.

Five, add three label controls and three text box controls below the command button control, and set the value of the Caption property of the three label controls to "eligible people", "total wages", and "average wage" in turn. Line up the controls and cross the Label control and text box controls in turn.

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

Eight, set the properties of the combo box control:

(a) combo box Combo1:recordsourcetype property value is set to "8-structure" and the RecordSource property value is set to personnel information table.

(ii) combo box Combo2:recordsourcetype property value is set to "N" and the RecordSource property value is set to ",>,<,=,>=,<=,<>".

Nine, add the event code:

(i) Init event code for the form:

Set Talk off
Thisform.text2.value=reccount ()
SUM (base salary) to Thisform.text3.value
Aver (basic salary) to Thisform.text4.value

(ii) Unload event code for the form: close data

(iii) Interactivechange event code for combo box Combo1:

If Alltrim (this.displayvalue) = "Birth date"
   thisform.text1.value={}
else
   thisform.text1.value= '
endif

(iv) The Click event code for the "Statistics" button Command1:

If thisform.grid1.recordsource= ' Temporary staff information table ' thisform.grid1.recordsource= ' personnel information table ' endif private cxtj if empty (thisform.com
   Bo1.displayvalue) or empty (Thisform.combo2.displayvalue); or empty (thisform.text1.value) && Determine if the list box and text box are empty MessageBox (' Enter the full condition! ', 16, ' system hint ') Thisform.combo1.setfocus else does case alltrim (thisform.
	Combo1.displayvalue) = ' Basic Salary ' Cxtj=alltrim (thisform.combo1.displayvalue) + ';
	+alltrim (Thisform.combo2.displayvalue); + ' +alltrim (thisform.text1.value) Case Alltrim (thisform.
	Combo1.displayvalue) = ' Birth date ' Cxtj=alltrim (thisform.combo1.displayvalue) + ';
	+alltrim (Thisform.combo2.displayvalue);
	+ ' Ctod ("' +dtoc (thisform.text1.value) + '") ' otherwise Cxtj=alltrim (thisform.combo1.displayvalue) + ';
	+alltrim (Thisform.combo2.displayvalue); + ' "' +alltrim (thisform.text1.value) + '" ' endcase Select * from personnel information table where &AMP;CXTJ. into cursor temporary personnel information Table thisform.grid1.recordsource= ' Temporary personnel Information table ' Thisform.grid1.backcolor=rgb (200,224,248) Sele Temporary Staff Information Table Thisform.text2.value=reccount () sum (basic salary) to Thisform.text3.value aver (base salary) to THISFO Rm.text4.value endif

(v) "Exit" button Command2 Click event Code: Thisform.release

Run "The statistical calculation of the results of the query. 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.