Você está na página 1de 6

CHAPTER 12

COMMAN D FILE COMMAN DS


A database program or command file is simple, a series of commands stored in a file. The file which stores commands in them are called command file or program file. SYNTAX MODIFY COMMAND < file name > While giving the filename the extension as .prg. The length of the file name should be 8 characters. Example : MODIFY COMMAND TEST After executing this command, it opens Text area to type .prg instructions. The file name as TEST.PRG. Press Ctrl-W to save the instructions in file. DO COMMAND To

e x e c u t i v e t h e p r o g r a m f i l e ( . P R G ) , t h e c o m m

and used is DO < file nam e> Exa mpl e

DO TEST D O

S T U D E N T NOTE, * && The asterisk character (*)is used to insert comment lines. This can be used to display the name of the command file or to explain command files with descriptive comments about the purpose of following command lines. *the program of finding the biggest number* NOTE The Note command does precisely the same thing as the asterisk

(*) charact er and can be used intercha ngeably . To continu e to comme nt on the followi ng line, semicol on (;) should be used at the end of first comme nt line. NOTE T h i s c o m m e n t l i n e i s f o r ;

I n f o r m a t i o n p u r p o s e o n l y & & This is another comment designator that can be used to insert comments on the same line as a command. The FoxPro command interpreter ignores the && and following text. Example: Wait && pauses and displays "press any key to continue" PRINT STATEMENT ? The question mark is used to print the message or variables and the question mark with- any message or variables indicate to display a blank line. Example : ? "Name of student"'. Name > ?? expression : The double marks causes text to print on the same line. ??? expression :

The three questions marks direct the contents of the expression directly to a printer without lung it through a printer driver. This is useful because it allows you to use printer codes that not supported by the printer driver. MPLE PROGRAMS To assign any 3 numbers and print the same Clear Store 0 to A.B.C A=5 B= 10 C= 15 ?A ?B ?C Example To assign any 2 numbers and find the sum, product, ratio and difference and print the MB. CLEAR STORE 0 TO Nl, N2, SUM. PRO. DIE RAT STORE 100 TO Nl STORE 50 TO N2 SUM = Nl + N2 PRO = Nl * N2 DIF = N1-N2 RAT = N1-N2 ?"SUM OF TWO NUMBERS = **, SUM TTRODUCT OF TWO NUMBERS = ". PRO ? -DIFFERENCE OF TWO NUMBERS = ". DIF ?RATIO OF TWO NUMBERS = ", RAT

>

ACCEPT & INPUT


The ACCEPT and INPUT commands are useful in command file.

ACCEPT This command is used to accept the character type data memory variable from the user through the Keyboard after executive the program. SYNTAX ACCEPT < "expression'^ TO <variable> Example ACCEPT "Enter students name" To name INPUT This command is used to input a numeric memory variable from the user through the Keyboard after executive the program. INPUT "Enter the marks" TO mark INPUT "Enter the Sales amount " TO sale_amount Example

To Input any 2 numbers and find the sum, product, ratio and difference and print the results. CLEAR STORE 0 TO Nl, N2, SUM, PRO, DIF, RAT INPUT "ENTER FIRST NUMBER = " TO Nl INPUT "ENTER SECOND NUMBER = " TO N2 SUM = Nl + N2 PRO = Nl * N2 DIF = N1-N2 RAT = N1-N2 ?"SUM OF TWO NUMBERS = ", SUM ?"PRODUCT OF TWO NUMBERS = ", PRO ? "DIFFERENCE OF TWO NUMBERS = ", DIF T'RATIO OF TWO NUMBERS = ", RAT

> IF - ENDIF
This set of commands form a complete branching statement SYNTAX IF <expression> (command lines) ENDIF example IF A>B ? "A is Big", A ENDIF Ixample To input any 2 numbers and find the biggest number * STORING THE VALUES * STORE 0 TO A,B * INPUTTING* INPUT "ENTER THE VALUE OF A" TO A INPUT "ENTER THE VALUE OF B" TO B * CHECKING * IF A>B ? "A IS BIG" ENDIF IF B>A ? "B IS BIG" ENDIF

> IF - ELSE - ENDIF


The else statement is an optional command that adds branching to IF statement SYNTAX IF <expression> (command line) | ELSE (command line) ENDIF Example

To input any two numbers and find the smallest one STORE 0 TO A, B INPUT "ENTER THE VALUE OF A" TO A INPUT "ENTER THE VALUE OF B" TO B CHECKING* IF A<B ? "A IS SMALL", A ELSE ? "B IS SMALL ", B ENDIF Example To input any NO. and find whether the given number is positive or negative. * TO FIND INPUTED NUMBER IS + ve OR - ve INPUT "ENTER ANY NUMBER :" TO NUM IFNUM = 0 ?" INPUETD NUMBER IS ZERO" , NUM ELSE IF NUM > 0 ? " NUMBER IS POSITIVE ", NUM ELSE ? " NUMBER IS NEGATIVE ", NUM ENDIF ENDD7

> NESTED IF - ELSE - ENDIF


IF <expression> IF <expression> Statement ELSE Statement ENDIF ELSE IF <expression> Statement ENDIF ENDIF

> LOGICAL OPERATORS


There are 3 types of logical operators 1) .AND. 2) .OR. 3) .NOT.

> IF - ENDIF WITH .AND.


SYNTAX IF expression 1> .AND. expression 2> .AND. expression 3> < True body> ENDIF <Statement x>

Você também pode gostar