Look at the case study VFP: Modify the records in the datasheet

Source: Internet
Author: User
Tags empty

In this case, the text box on the form used to receive data is hidden, the Modify button is disabled, as shown in the following figure:

Select the field you want to find in the combo box, click the Find button on the right after you enter the lookup in the text box, and then the Find button is disabled, and the Modify button and the text box to receive the data are activated. and displays the value of the current record (the record that satisfies the query criteria) in the text box, as shown in the following figure:

When you click the Modify button, the value you enter is judged. If a non-empty condition is met, the current record value of the site information table is modified with the value in the form text box, and GRID1 is refreshed when it is finished, and the Modify button is disabled again, activating the Find button and hiding the Receive data text box.

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.

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 226,autocenter property value set to. T, and save it as " Modify the records in the datasheet. 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 modify in turn.

Six, add three label controls below the command button, line the three label controls, and set their Caption property to number, site name, and site URL.

Seven, add three text box controls below this line of label controls, the property values are default, and the three text boxes are lined up in one line.

Eight, adjust the position of the controls on the form, and the Adjusted form designer follows the following figure:

Nine, add the event code:

(i) Unload events for form Form1:

Set Exact off
Close data

(ii) Init event for form Form1:

Set exact on
this.command1.enabled=.t.
This.command2.enabled=.f.
This. Text2.visible=.f.
This. Text3.visible=.f.
This. Text4.visible=.f.
This. Label3.visible=.f.
This.label4.visible=.f.
This. Label5.visible=.f.
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
this.grid1.Setall ("Dynamicbackcolor", "RGB (224,225,255)", "Column")

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

If empty (thisform. Text1.value) =.f. Go top A=thisform.combo1.value B=alltrim (thisform.
  Text1.value) c=.f. 
      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") go
     Else c=.t. 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 hint") g
     o Top return else c=.t. endif endif if a= "website url" Locate for Web site =b if EOF () MessageBox ("The record you want to query does not exist in the database", 16, "system hint") g
     o Top return else c=.t. endif endif if C thisform.
     Text1.enabled=.f. Go Recno () thisform.
     text2.visible=.t. Thisform.
     Text2.enabled=.f. Thisform.
     text3.visible=.t. Thisform.
     text4.visible=.t. Thisform.
     label3.visible=.t.
     thisform.label4.visible=.t. Thisform.
     label5.visible=.t. Thisform. Text2.value= Web site Information table. Thisform number. Text3.value= Web site Information table. The website name Thisform. Text4.value= website LetterWeb site Thisform.grid1.setfocus this.enabled=.f.
  thisform.command2.enabled=.t. endif Else MessageBox ("Please enter the content you want to find!") ", 16," system hint ") thisform. Text1.value= "" Thisform. Text1.setfocus endif Thisform.refresh

(iv) Click event for the Modify button (Command2):

A=alltrim (thisform. Text3.value)
B=alltrim (thisform). Text4.value)
if Empty (a). Or.empty (b)
   MessageBox ("website name and website URL can not be modified to null value", 16, "system hint")
   return
endif
Msg=messagebox (' Are you sure you want to modify the record? ', 32+4, ' system hint ')
if msg=6 go 
   recno ()
   Replace Web site information table. Site name with a, site information table. Web site
   with b MessageBox ("Modify record Successful", 16, "system hint")
   Thisform.grid1.refresh
   thisform.command1.enabled=.t.
   Thisform. text1.enabled=.t.
   This.enabled=.f.
   Thisform. Text2.visible=.f.
   Thisform. Text3.visible=.f.
   Thisform. Text4.visible=.f.
   Thisform. Label3.visible=.f.
   Thisform.label4.visible=.f.
   Thisform. Label5.visible=.f.   
   Thisform. Text1.value= ""
   thisform. Text1.setfocus
endif

Run "Modify the records in the datasheet. Scx".

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.