Tutorials to .com

Tutorials to .com » Database » Foxpro » VFP edit box method for automatic correction

VFP edit box method for automatic correction

Print View , by: iSee ,Total views: 17 ,Word Count: 2512 ,Date: Sat, 18 Apr 2009 Time: 11:06 PM

Introduction

We use Word2000 edit a document, can be a tool in Word2000 menu item AutoCorrect feature set, the primary role of this function when a user is editing a document, when the input data is not a correct phrase, the Word2000 will automatically enter the correct phrase is not corrected for the content of the right phrase, thus greatly improving the accuracy of input of Chinese characters. Automatic correction function in the window, the window can be seen, including automatic correction of a mistake is the content of the control data, the use of the process the user can use the system to correct the default data content, but also can increase or modify the contents of a correction data, such In editing the document, the use of this feature is very convenient to use. According to this the realization of the principle, we can use this function to the vfp database management system from the application of the preparation processes, can improve the system in a text editor to write text to deal with the correctness of the time, introduced the author of this text the following automatic the realization of the process of correction function.

System Principle

In order to achieve the error text is replaced mutual information function can be corrected in accordance with the method of Word2000 to achieve the establishment of a correct manner the contents of the database, the database will be collected in those prone to error when writing the phrase written information. However, we can think of, if collected by the user of the database, by personal knowledge and application of the field restrictions, collected workload will be very great, in practice can not be easy to achieve. In fact, this system can use Word2000 collected in the control of the information is wrong, this part of the transition to the actual needs of the database generated, which would greatly enhance the efficiency of collection. Word2000 so we must first of these is stored in the storage of data error control file to find out, by looking to know the documents folder C: / Windows / Application / Microsoft / office / under the file name for ms01033.acl, in order not to affect the Word2000 proper use, you can copy this file to the root directory of c and changed the name of the file suffix DOC, into Word2000 document file type, and then use Word2000 to open the document, there are generally prompted to insert the installation disk OFFICE2000, Users can insert the installation disc to install the code content, and then select an appropriate code to open the file, here is the need to select Unicode encoding, and then open the document, you can see the document open in the back part of the existence of all control the misuse of Chinese characters are written materials, this part can copy text out of all the information stored in a plain text file, and to this plain text file named ZL.TXT, in this text file stored Word2000 all the Chinese term correction information, and then this text will require the information to the contents of the conversion to a database, where a small process can make use of such data conversion.

Create a new file named data table ABC.DBF, the data table file includes two fields only NR1, NR2 field for the character, width of 30, after the establishment of this data, the establishment of a program file MAIN.PRG, procedures reads as follows:

USE ABC
WJNR=FILETOSTR ("C:/ZL.txt")
WJNR=WJNR+" "
DO WHIL LEN (ALLT (WJNR))>0
NR11=SUBS (WJNR, 1,AT (" ", WJNR))
WJNR=SUBS (WJNR, at (" ", WJNR)+2)
NR22=SUBS (ABC, 1,AT (" ", WJNR))
WJNR=SUBS (ABC, AT (" ", WJNR)+2)
SELE ABC
APPE BLAN
REPL NR1 WITH NR11, NR2 WITH NR22
ENDDO
USE ABC
WJNR=FILETOSTR ("C:/ZL.txt")
WJNR=WJNR+" "
DO WHIL LEN (ALLT (WJNR))>0
NR11=SUBS (WJNR, 1,AT (" ", WJNR))
WJNR=SUBS (WJNR, at (" ", WJNR)+2)
NR22=SUBS (ABC, 1,AT (" ", WJNR))
WJNR=SUBS (ABC, AT (" ", WJNR)+2)
SELE ABC
APPE BLAN
REPL NR1 WITH NR11, NR2 WITH NR22
ENDDO
USE ABC
WJNR=FILETOSTR ("C:/ZL.txt")
WJNR=WJNR+" "
DO WHIL LEN (ALLT (WJNR))>0
NR11=SUBS (WJNR, 1,AT (" ", WJNR))
WJNR=SUBS (WJNR, at (" ", WJNR)+2)
NR22=SUBS (ABC, 1,AT (" ", WJNR))
WJNR=SUBS (ABC, AT (" ", WJNR)+2)
SELE ABC
APPE BLAN
REPL NR1 WITH NR11, NR2 WITH NR22
ENDDO

After running this program to open data sheet ABC.DBF, Word2000, we can see all the characters under the corrected information to the data conversion, in which storage of NR1 in the content of the information is wrong, NR2 is stored information corresponding to the correct content, and then you can take advantage of this data sheet is wrong in the control of the content of documentation to achieve the automatic correction feature.

Specific procedures to achieve

Following a simple example to introduce this feature in the procedure to correct the specific method:

Create a new form, the data in table form to join the ABC data environment, and then placed in the form of a text edit box EDIT1, adjust the edit box to the right location, in the edit box of the data source can be a data table in the Remarks field name, it can be a variable, the user can be in this edit box enter some text, and then in the edit box KEYPRESS events in EDIT1 enter code as follows:

GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF
GBWZ=THISFORM.EDIT1.SELSTART&&
IF GBWZ>4 &&
THISFORM.LockScreen = .T.
CXNR1=SUBS (THISFORM.EDIT1.VALUE, GBWZ-7,8)
CXNR2=SUBS (THISFORM.EDIT1.VALUE, GBWZ-9, 10)
CXNR3=SUBS (THISFORM.EDIT1.VALUE, GBWZ-11, 12)
CXNR4=SUBS (THISFORM.EDIT1.VALUE, GBWZ-13, 14)
CXNR5=SUBS (THISFORM.EDIT1.VALUE, GBWZ-15, 16)
CXNR6=SUBS (THISFORM.EDIT1.VALUE, GBWZ-17, 18)
CXNR7=SUBS (THISFORM.EDIT1.VALUE, GBWZ-19, 20)
CXNR8=SUBS (THISFORM.EDIT1.VALUE, GBWZ-21, 22)
&&4-11,411,。
SELE ABC
LOCA FOR ALLT (CXNR1)= =ALLT (NR1) OR ALLT (CXNR2)= =ALLT (NR1) OR; ALLT (CXNR3)= =ALLT (NR1) OR ALLT (CXNR4)= =ALLT (NR1) OR;
ALLT (CXNR5)= =ALLT (NR1) OR ALLT (CXNR6)= =ALLT (NR1) OR;
ALLT (CXNR7)= =ALLT (NR1) OR ALLT (CXNR8)= =ALLT (NR1)
&&IF FOUND()&&ZDZ=LEN (ALLT (NR1))
THISFORM.EDIT1.VALUE=SUBS (THISFORM.EDIT1.VALUE, 1,GBWZ-ZDZ)+;
ALLT(ABC.NR2)+SUBS(THISFORM.EDIT1.VALUE,GBWZ+1)&&THISFORM.EDIT1.REFRESH
THISFORM.EDIT1.SELSTART=GBWZ
ELSE
THISFORM.EDIT1.SELSTART=GBWZ
ENDIF
THISFORM.LockScreen = .F.
ENDIF

All content input has been completed, run the form, and in the form of text edit box when the user enters a wrong phrase data, the contents of the edit box will be automatically corrected for the correct phrase information with the use of Word to use the same, so that we have achieved in the edit box of the AutoCorrect feature of Chinese characters. Of course, in the system can also increase the changes of the corrected data, adding such operation, this system will be more convenient to use.

Concluding remarks

This article provides a realization of text edit box VFP data errors automatically corrected method, the routine does not consider fault-tolerance, according to this principle can be useful to prepare more complete applications, interested readers can try.


FoxPro Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.