Looking at the case study VFP: Locating and locating the records in the table

Source: Internet
Author: User
Tags query

In VFP operation table record, can use the SQL statement, can also use the built-in append, replace, Delete/pack/zap, and other commands and with some record pointer positioning and data sorting commands and functions to use, and in vb/vb.net, use ADO /ado. NET and the properties and methods are available. VFP is as flexible as the C language, but perhaps it is because of this that many of those who have just contacted her feel nowhere to start and then dislike her. VFP like a homely, introverted lady, not everyone will like her, only to understand her strengths will fall in love with her.

That's a little off the track, now. From the beginning of this article will give some examples of the use of VFP built-in Statement action table, and then give some examples of using SQL statements to do the same operation. This article is an example of a query table record, the runtime can freely select the field by which the query is based in the combo box by setting the properties of the combo box control and judging the user's selected value in the command button's Click event code, which has the ability to verify the input data of the text box. And if the database exists the queried records will return the query results, otherwise the prompts will be given.

When this example starts, all records in the Web site information table are displayed in the grid. At run time you can select the field you want to find in the combo box, and then click the Find button on the right side of the text box to locate the lookup and display the search results in the table above; click Restore The button table control resumes displaying all the records in the Site information table. About VFP table record pointer positioning and data sorting please refer to: Record pointer positioning and data ordering, this example uses the "Data 1" database "website Information table", about the situation of the database is already looking at the case of VFP: sample database in a text given, here are no longer detailed, only briefly introduce the production process.

This example runs the following diagram:

The production steps are as follows:

First, create a new form Form1 and set its Caption property to "Locate and locate records in a table", set the Width property value to the 290,height property value set to the 165,autocenter property value set to. T, and save it as " Locate and find operations on records in a table. Scx ".

Add a Grid control to the form, set its ReadOnly property to. T, and its recordsourcetype value with the default "1-alias", and in the form designer, width and height, and then roughly lower it, Specific attribute values we will set them in the form's Init event code.

Third, add two label controls below the grid control, line them in one row, and set their Caption property to "Select Find how" and "Enter what you want to find."

Four, add a combo box control below the label control Combo1 and a text box control Text1, the text box control's property value is the default, the combo box control Combo1 's RowSourceType property value is set to "N", and the RowSource property value is set to " Number, website name, website url "so that at runtime we can select the fields to query in the combo box.

Five, add two command buttons Command1 and Command2 on the form, and set their Caption property to find and redo. Adjust the position of the controls on the form appropriately, as shown in the following illustration:

Vi. Add event code:

(i) The Unload event code for the form Form1:

Set Exact off
Close data

(ii) The Init event code for the form Form1:

Set exact on the Use
Web site information table this
. Combo1.value= "numbered" with Thisform.grid1. width=290. height=100 left=0.
    top=0
    . Recordsource= "website Information table"
    . Deletemark=.f.
	visible=.t..
	readonly=.t..
	Columncount=3
    . column1.header1.caption= "Number"
    . Column1.header1.backcolor=rgb (255,255,190)
    . Column2.header1.backcolor=rgb (255,255,190)
    . column2.header1.caption= "website name"
    . Column3.header1.backcolor=rgb (255,255,190)
    . column3.header1.caption= "website url"
    . Column1.width=75
    . Column2.width=80
    . column3.width=150
endwith
thisform.grid1.Setall ("Dynamicbackcolor", "RGB (224,225,255)", "Column")

(iii) Click event code for the Find button (Command1):

If empty (thisform. Text1.value) =.f.
Go top
a=thisform.combo1.value
B=alltrim (thisform. Text1.value)
  if a= "numbered"
     locate for number =b
     if EOF ()
        MessageBox ("The record you want to query does not exist in the database", 16, "System Prompt")
     else Go
        recno ()
     endif
  endif
  if a= "site name"
     Locate for Site name =b
     if EOF ()
        MessageBox (" The record you want to query does not exist in the database ", 16, System prompt"
     else go
        recno ()
     endif
  endif
  if a= "website url"
     Locate for Web site b
     if EOF ()
        MessageBox ("The record you want to query in the database", 16, "System Prompt")
     else Go
        recno ()
     endif
  endif
  Thisform.grid1.setfocus
Else
   MessageBox ("Please enter the content you want to find!") ", 16," system hint ")
   thisform. Text1.value= ""
   thisform. Text1.setfocus
endif
return

(iv) Click event code for the Restore button (Command2):

Go top
thisform. Text1.value= ""
thisform. Text1.setfocus with
thisform.grid1.
    width=290
    left=0
    . top=0 "Site Information table"
	. visible=.t.
	readonly=.t..
	Columncount=3
    . column1.header1.caption= "Number"
    . Column1.header1.backcolor=rgb (255,255,190)
    . Column2.header1.backcolor=rgb (255,255,190)
    . column2.header1.caption= "website name"
    . Column3.header1.backcolor=rgb (255,255,190)
    . column3.header1.caption= "website url"
    . Column1.width=75
    . Column2.width=80
    . column3.width=150
endwith
thisform.grid1.Setall ("Dynamicbackcolor", "RGB (224,225,255)", "Column")
Thisform.refresh

Run "Locate and find operations on records in a table. Scx", you can achieve the effect of this example.

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.