Look at the example of VFP: adding records to a datasheet and verifying that the input data is legitimate

Source: Internet
Author: User
Tags exit in

In this example, the execution of the procedure is to use the empty () function to determine whether the text box is empty when the record is added, and to use locate to do record pointer positioning (refer to the VFP table record pointer positioning and data ordering), and to determine whether or not to duplicate the data already in the table. Complete the data checksum in the above manner, and if a non-empty, repeatable condition is met, use the Append blank command to add a blank record to the table, and then use the Replace command to modify the value of the corresponding field of the record to the value entered in the corresponding text box on the form. When the program is run, the following figure:

This example uses the "Data 1" database "Web site information table", about the database is already looking at the case of VFP: sample database, given in the article, no longer detailed here.

The production steps are as follows:

First, create a new form Form1 and set its Caption property value to "Add a record to a datasheet and verify that the input data is valid", the AutoCenter property value is set to. t.,widht property value set to 290,height property value set to 225, save it as " Add records to the datasheet and verify that the input data is valid. 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, adds three label controls to the form, with the property values set to number, site name, and site URL, one row, and three text box controls below this line of label controls, with the property values not set, default , add two command buttons Command1 and Command2 below the text box, and the Caption property values are set to add and exit in turn. The form designer, after adjusting the position of each control appropriately, is shown in the following illustration:

Iv. Add event code:

(i) Unload events for form Form1:

Set Exact off
Close data

(ii) Init event for form Form1:

Set exact on the Use
Web site information table this
. Text1.value= "" This
. Text2.value= "" This
. Text3.value= "" With This.grid1 width=290. left=0. top=0
    " 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) The Click event code for the command button Command1 (add button):

A=alltrim (thisform. Text1.value) B=alltrim (thisform). Text2.value) C=alltrim (thisform).
  Text3.value) if empty (b) && This condition indicates that the text box is empty messagebox ("Please enter site name", 16, "System Prompt") return to locate for site name =b If. not.eof () && This condition indicates that the content to be added and the table has a duplicate go top MessageBox ("Do not allow duplicate site names", 16, "System hints") thisform. Text1.setfocus return endif endif if empty (c) MessageBox ("Please enter Web site URL", 16, "System Prompt") return to else locate for website URL = c If. not.eof () Go top MessageBox ("Do not allow duplicate site URLs", 16, "System hints") thisform.
  Text1.setfocus return endif endif if Empty (a) =.f. Locate for number =a if. not.eof () go to top MessageBox ("Do not allow duplicate site number", 16, "System Prompt") thisform. Text1.setfocus return Else Msg=messagebox (' Are you sure you want to add a record? ', 32+4, ' system hint ') if msg=6 append blank go bottom Replace Web site information table. Number with Alltrim (thisform.
	Text1.value),; Web site Information table-site name with Alltrim (thisform.
	Text2.value),; Site Information table-Web site with Alltrim (thisform. Text3.value) MessageBox (' Save record Success! ', 64, ' system hint ') thisforM.text1.value= "" Thisform. Text2.value= "" Thisform. Text3.value= "" Thisform.refresh endif endif Else MessageBox (' Please enter the number of the site! ', 16, ' system hint ') endif

(iv) Click event code for command button Command2 (Exit button):

Msg=messagebox (' Are you sure you want to exit the system? ', 32+4, ' system hint ')
if msg=6
 thisform.release
endif

Run "Add a record to the datasheet and verify that the input data is valid. 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.