Tutorials to .com

Tutorials to .com » Database » Foxpro » VFP chapter Essentials language based on VFP

VFP chapter Essentials language based on VFP

Print View , by: iSee ,Total views: 24 ,Word Count: 3059 ,Date: Sat, 18 Apr 2009 Time: 3:37 PM

2.1 Programming overview

1. Programming Introduction

Design Method Key concepts Design process Procedures for implementation
Structured Programming Functional modules (that is, the process of self-defined function) The preparation of various functional modules, and then string them up the main program application procedures will be broken down into several functional modules, each module through the call to complete the entire implementation process is process driven.
Object-oriented programming Categories, objects, properties, events, methods Design categories, sub-class, object (the design of appearance, set attributes, methods of procedure for the preparation of the incident) The application with specific attributes into the object, by calling the object in different ways to complete the related events is event-driven.

2. Data Type

vfp data types include the following:

Common data types Character

Character

Currency type

Currency

Date Type

Date

Date Time Type

DateTime

Logic-based

Logical

Numerical model

Numeric

Only the data type for the field Double-precision type

Double

Floating-point type

Float

Integer

Integer

General-purpose

General

Type Remarks

Memo

3. Data Container

VFP in containers used to store data are: constants, variables, arrays, records and objects.

(1) constants (constants):

In the course of an operation remain the same value or string.

Types of commonly used constants

Constant type Numeric constants Character constants Logical constants Date Type Constants
That way -25.36 "abc", "123", "China" . T.. F. (^ 2005/07/10)

(2) variable (variables):

Is the memory location of a memory cell, in which the content can change, but the logo of the name of the storage location (that is, variable names) remain unchanged.

Habit of naming variables: the type of variable code

Such as: cStud, nCj, dCsrq --

Representing a character, numeric, date, type the variable name

Assign variables: 1) using STORE command such as: STORE "Wang" TO cStud

2) if the assignment operator =: cStud = "Wang"

The scope variables: namely, the effective use of variables from the scope.

Variable scope Scope of the definition of keywords Features
Local variables

local variable (local variables)

LOCAL Only in a function or process has been to visit, and other process or function can not access the variable data. When to stop running their own procedures, the local variables will be released.
Private variables

private variable

PRIVATE Private variables in VFP is the default, does not require the definition of special keywords. However, if at a higher level routines (routine) in the variables have the same name can be a statement PRIVATE keyword to limit its scope. When the definition of routine end of this variable, this variable has also been a corresponding release. Use of private variable function calls in the shared data.
Public variables

public variable

PUBLIC Can be used for all processes and functions, but not limited to the process of definition of the variables and functions. Can be used in a number of global variables or function between the process of sharing data, in order to create any window automatically has a global attribute variables.

Variable access:

When the variables and fields of the same name, the field has been given priority access. In the variable name before the m. or m -> to show the difference, such as m.cStud

(3) array (array):

Is stored in a variable by a single variable name referenced data sets in an orderly manner. In VFP, the data in an array need not be the same data types. Commonly used are one-dimensional array, two-dimensional array.

Array of marking elements: a numerical subscript to refer to, such as AA [2], AA [2,3]

Array type declaration:

Private array - with the definition DECLARE or DIMENSION

Global Array - life with the definition of PUBLIC

Local arrays - with the definition of LOCAL

Assign the array elements:

With assignment statements: If AA = 45

SCATTER with records taken from the current value of specific fields assigned to the array:

Such as: scatter fields xh, xm, xb to aa

(Array length, the type of automatic with the same to the field)

COPY TO ARRAY with records taken from the current value assigned to all fields array:

Such as: copy to array aa

(Array length, the type of automatic field with the table all the same)

The data in the array to the current table of the current record:

gather from an array of [fields list of fields]

Table with an array of add to the current record:

append from array Array of [for the conditions of] [[fields list of fields]

(Two-dimensional array can be used to add more records)

Commonly used array processing function:

Sort SORT (), search ASCAN (), delete ADEL (), insert the AINS ()

(4) record:

His table, composed by the field.

(5) object:

Is kind of an example is to have certain behavioral characteristics of data and the object of a description of the collection. VFP object can be a form, form set, control.

2.2 VFP 6.0 language components

1. Order

Namely: by the user, some operating instructions VFP instructions.

If USE aaa & open a data table aaa.dbf

2. Functions

Namely: the preparation of a pre-good module, VFP program can be called in any place.

The use of function: the name, functions, parameters, return values

Several commonly used functions

Name

Command format

Example

Interception string function SUBSTR (expC, expN1 [, expN2])

? SUBSTR ( "ABCDEFG", 2,4)

The result is: BCDE

LEFT (expC, expN) ? LEFT ( "ABCDEFG", 2) The result is: AB
RIGHT (expC, expN)

? RIGHTT ( "ABCDEFG", 4)

The result is: DEFG

Find string function AT (expC1, expC2 [expN]) ? AT ( "B", "ABCDE") result: 2

? AT ( "A", "ABCDEASD")

The results are: 1

? AT ( "A", "ABCDEASD", 2)

The result is: 6

Transfer function upper and lower case letters

LOWER (expC) ? LOWER ( "DFGHa") result: dfgha
UPPER (expC) ? UPPER ( "asdf") result: ASDF
Numerical function MAX (exp1, exp1 [, exp3, ...]) ? MAX (15,23,4,56) The result is: 56
MIN (exp1, exp1 [, exp3, ...]) ? MIN (15,23,4,56) The result is: 4
ABS (expN) ? ABS (-15.83) result: 15.83
INT (expN) ? INT (25.62) The result is: 25
Compression function spaces ALLTRIM (expC)

? ALLTRIM ( "AD BG")

The result is: AD BG

Type conversion function STR (expN1 [, expN2] [, expN3]) ? STR (789.678,6,2) The result: 789.68
CTOD (expC)

? CTOD ( "98/10/15")

The result: 98/10/15

VAL (expC) ? VAL ( "123.45") The result: 123.45
DTOC (expD)

? DTOC ((98/12/15))

The result: 98/12/15

Date Time Function DATE () ? DATE () result: 2000/03/15
DATETIME ()

? DATETIME ()

The result is: 2000/03/15 10:15:30

YEAR (expD) ? YEAR ((87/03/25)) The result: 1987
database function RECNO () DBC () SEEK ()

Other functions

LEN () DELETED ()
EOF () BOF () FOUND () EMPTY (exp) INLIST (,,)
RECCOUNT () SELECT () BETWEEN (,,) IIF (,,)
TABLEREVERT () LOCK () CHR () ASC ()
TABLEUPDATE () FSIZE () TAG () INKEY ()

Defined functions:

By the user for their own applications to create a special function, can be used as an independent program file stored in the disk can also be used as the process of documents in other proceedings.

3. Expression

Namely: variables, operators, constants, functions, field names, control, and a combination of attributes, and the value of the results of a single value.

The type of expression:

Arithmetic expressions: Arithmetic Operators and from data consisting of numerical expressions.

Character expression: by the operator and the character of characters consisting of expression data.

Date of expression: from the date of operator and the date, time of expression data poses.

Logical expression: by the logic operator and the logical expression data posed.

The name of the expression:

By the parentheses enclose the expression of a character to replace the command or function name.

Cases: DBF_NAME = "Registration Form pupils"

USE (DBF_NAME)

Acer Replacement: The replacement of symbols & Wang said that it has a name similar to the role of expression.

For example: the known A = "1", B = "2", C12 = "GOOD"

The c & A & B = "GOOD"

4. Operator

Numerical Operators () ^ Or ** * / % (Balance check) + --
The relationship between operator < <= > > = <> Or! = Or # = =
Logical Operators () Grouping regular expression Or NO! (Non-) AND (and) OR (or)
The date and time of operator + -- Note: Date type: the number of days of time-based: the number of seconds
Operator characters: + -- $
Two special operator Dot operator (.): The name of the object used to separate and the separation of the properties of objects, events, and methods.
Changes in the scope of the provision of operator (::): a subclass from a parent to call the method.

2.3 Design procedure

1. The basic concepts of

Procedure: In order to solve the problem of designing a series of commands.

Main program: is usually direct the implementation of procedures.

Subroutine: In the process of the procedure is called.

Source: from the source language with the computer program must be translated into machine language before execution.

Goal of the procedure: It is compiled source code generated by the machine language program.

Executable program:

Source code was compiled can be machine generated by the implementation of the procedures directly with. EXE extension. Is in VFP project manager means for generating even and can be run from the VFP environment procedures.

Applications:

Refers to the specialized work for the completion of the design of a group of interrelated routines and subroutines. VFP is in a group of Visual foxpro procedures, forms, menus and other documents for the project manager even after the formation of a single procedure can not be run from the VFP environment, extension. APP.

Routine:

By some sort of order so that the computer can perform certain tasks instruction set, can be a dedicated program or as part of the procedures. It may be composed of several sub-procedures.

2. Control

(1) the order of statements

That is, in accordance with the procedure in order to implement the statement.

(2) branch statement

Conditional statements: Case statement:
IF condition

Command group 1

[ELSE

Command group 2]

ENDIF

DO CASE

CASE 1

Command group 1

CASE 2

Order 2

...

[OTHERWISE

Other command group]

ENDCASE

3. Loop

FOR

Loop (predictable cycles)

FOR variable = initial value TO end [STEP step]

Command group

ENDFOR | NEXT

DO WHILE

Statement cycle (cycle number unknown)

DO WHILE condition

Command group

ENDDO

SCAN

Loop (for all records)

SCAN [scope] [FOR | WHILE condition]

Command group

ENDSCAN

Cycle structure of the LOOP and EXIT command command:

LOOP is a short statement that began the next cycle;

EXIT from the statement is that out of the cycle.

4. Subprogram

Could take the form of the subroutine is a program file, it can be a process or user-defined functions.

Subroutine Custom function Process
Features Always call other programs rather than separately, you can call other subroutines, do not have to return a value. To an independent document storage can also be included in the call process, must return a value. Is a program segment is an integral part of the procedure, generally on the end of the process.
The definition of methods And procedures is the same as the increase at the end of the subroutine to be a return to order:

RETURN [expression | TO MASTER | TO program file name]

FUNCTION function name

Or: MODIFY COMMAND function names

PARAMETERS Table

Command group

RETURN expression

Note: The definition of the function of this command to save the form of stand-alone document.

PROCEDURE procedure name

PARAMETRS parameter table

Command group

RETURN

Call method DO subroutine name [WITH parameter table] = Function of (parameter table) DO process parameter table name WITH

3. To create applications

Method One:

Enter in the command window: MODIFY COMMAND procedures were

Method Two:

Click File menu → Programs → → New → a new document window in Edit → Editor → given after the completion of the closure of a proper procedure, and the preservation of the location.

Procedure Note: Method 1: * | NOTE <Note the contents> may appear in the proceedings of any local

Method 2: & & <Note the contents of> the general command of the tail for

Notes to the processes in order to improve the readability of the procedure.

Process-oriented program design trilogy: input → processing → output

4. To amend the application

Method One:

Enter in the command window: MODIFY COMMAND name |?

Note:? Said they did not know the procedure name, selected from the Open dialog box.

Method Two:

Click File menu → Open → select the desired program and open the editing window → procedure → after the completion of modifications to close out of.

5. The implementation of applications

Method One: In the command window, type: DO program name |?

Method 2: From the Programs menu → choose Select from the Open dialog box and implement the necessary procedures.

6. Programming the basic steps

(1) a description of the problem

(2) decomposition of the problem

(3) the preparation of the module

(4) to test and improve the module

(5) assembly of all modules

(6) the overall test


FoxPro Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.