Foxpro For MS-DOS - Basic FoxPro 2.6 Commands

Transcription

Foxpro for MS-DOS - Basic FoxPro 2.6 Commands FoxPro is SEMI-RDBMS Unlike other RDBMS systems, in FoxPro each database can contain only one table. Hence, the single table is called as database in this tutorialIn FoxPro, first four characters of any command is enough to executeFor e.g.:- crea create1. TO OPEN A DATABASE:Syn:use dbname Ex:use book2.TO CLOSE THE DATABASE:UseTo close the current opened database.Close allTo close the all opened database.3. To CREATE NEW DATABASE:Syn:crea dbname create dbname Ex:crea book

4. To Modify Structure of the Database:Modify structure(Or)Modi stru5. To add new records in databaseAppend is used to add the new record.Syn:append[Blank][From dbname ]ExAppendAppend Blank- To add blank records.Append from first.dbf- To add the records from FIRST.DBF to SECOND.DBF- Same Structure is required for these databases6. To display the records in the current databaseUsed to display the particular record.Syn:Display[All][Structure]

[Status][Memory]Ex:DisplayDisplay AllDisplay All Records in page wise.7. To Display the structure of the database:Display Structure8. To display the status of the set commands:Display Status9. To display the status of the system memory variables.Display Memory10. To view the status barSet stat on11. To edit recordsEDIT- It list all the records one by one for editing.Any one of the record can be edited using 'FOR' as belowEDIT FOR empname "LEELA"EDIT FOR rollno 10312. To delete recordsDELETE- To delete current recordDELETE NEXT 4- To delete next 4 recordsAfter using the delete command the records marked with * (asterisk) mark, i.e., marked for deletion.RECALL

- It is used to recover the deleted records.e.g. RECALLRECALL NEXT 4PACK- To delete the records permanently. It is used after the delete command.BLANK- It can be used to empty the record instead of deleting.13. To delete all the records in the current databaseZAP14. Navigation with RecordsGO or GOTO both do the same things in Foxpro.GO TOPUsed to move the record pointer at the first record.GO BOTTOM:Used to move the record point at the last record.GoTo go to a particular recordSyn:- GO recordno Eg:- GO 8Go to record 8SKIP- To skip number of recordse.g. To skip 3 records - SKIP 315. To List the recordsLIST - To list the records in screen, not in windowIt can be used with condition as below:LIST for val(price) 100

LIST itemname, price 20- This command lists item name with price rupees 20 added. The changes are applied only to the view, itnot saved in database.LIST product, price*2- price is multiplied with 2.16. To view the records as manipulatable viewBROWSE - To browse the recordsBROWSE NOEDIT - To browse the records in read only view, The records can be marked for deletionusing Ctrl T shortcutBROWSE NODELETE - To avoid deleting while browsing the records17. To display current record number?RECNO()18. To display the dbf files in the current directoryDIR19. Hide or Show heading in list viewSET HEADINGS OFFSET HEADINGS ON20. PrintingSET PRINT ON- This command sends the out put to printer- To stop this use the command SET PRINT OFFSET PRINTER TO LPT1- To set the output printing port to LPT121. Handling date and date formatTo display current system date

?DATE()To set century on to display year in 4 digits.SET CENTURY ONSET CENTURY OFFTo set date formatdd/mm/yyyy SET DATE BRITmm/dd/yyy SET DATE AMERICAyyyy/mm/dd SET DATE JAPAN22. Replace commandTo replace the content of the specified field in the database table. i.e., This command can be used toremove the data in the particular field (nullifying / empty a field)e.g.REPLACE fieldname WITH ""- To replace with null valueREPLACE fieldname WITH { / / }- To replace the date field with null valueREPLACE ALL QUANTITY WITH 0- Replaces the data in the quatity fied with 0 in all the records.REPLACE ALL PRICE WITH PRICE 50- Adds 50 to the price field.

23. BlankTo blank some or all the fields in the current record.BLANK- To blank all the fields in the current recordBLANK FIELDS field1 , field - To blank specified fields in the current recordPROGRAMA Program is a set of instructions used to achieve the desired output.To create new program or to edit the existing one.MODI COMMOR MODIFY COMMAND PRGRAM NAME NOTE commandIf ignore the particular line or command, NOTE can be used at the beginning of that line.Comment LineTo add comments to the right of the Programming code , use &&Clear All CommandThis command is used to closes all databases files and releases all active memory variables,arrays menus or popup.Input / Output command? ? ? [expr1?]?- To print the expression in new line?- To print the expression in the same line? - The Output will going to the printerExample:? "Hellow!"Sample ProgramNOTE prg for just print something on the screenClear&& To Clear the Screen or previous outputs?"Welcome"?"Hellow!"

? " World.!"? "Thank you”Writing Programs* FoxPro has powerful built-in editor for writingand editing.* It can be invoked from the command window by using the MODIFY COMMAND.Syntax:MODIFY COMMAND prenames Example:Modify Command journal(This program will automatically save with theextension .PRG)Press CTRL W - To save and close the program windowExecuting ProgramPrograms can be executed by DO command.Syntax:DO prgname Example:Do journalWhen compile the executed file the FoxPro creates an object code program with .FXP extension. Ifthere are any errors, creates a file an .ERR extension.INPUT commandIt is used to accept Numeric input from the user and store it into a memory variable.Syntax:INPUT [ char exp ] TO memvar Example:Store 0 to enoINPUT"Enter your Enrollment No : " TO eno? EnoACCEPT commandIt is used to accept character input from the user and store it into a memory variable.Syntax:ACCEPT [ char exp ] TO memvar Example:Store space (15) to NAM

ACCEPT "Enter the Name: " to NAM? "Entered name:” NAMExample 2clearSET TALK OFFAccept "Enter your nane :" to namInput "enter your Age : " to ageAccept " enter your city :" to citAccept "Enter your Mail id : " to mail? "******************************************"? "NAME :: " ,nam? "AGE:: " ,age? "CITY:: " ,cit? "MAIL ID:: " ,mail? g/restoring the environmentEvery FoxPro program includes all commands required to establish the working environmentand restore it to its prior state before the program terminates execution. This is achieved by issuingsome set.Set notify on/offEnables the display of certain system messages.Set talk windowDirectors the display of system messages to an user-defined window instead of the systemwindow. Sets notify should be ON.Set deleted on/offProcesses records marked for deletion.Input and output in foxproAs we already know that data can be entered into tables through the APPEND/BROWSEcommands. Data entry for tables can also be done through programs. There arises a need to displayand accept information in a formatted way.The @ say command is used to place data at a particular screen location and to display datastored in fields or memory variables. The @ get commands is used to retrieve data.Displaying data

@ say command: Syntax: @ Row, columns SAY expr [Function exprC1 ][Picture expr2 ][size exprn], exprn2 ][font exprC3 [, exprN3]][STYLE, exprC4 ]Example:@2, 10 say “hello welcome to FoxPro”Syntax:Input@row,column say char exp get mem var Output@row ,column say char exp get mem var Clear@row, column to row, column clearClear allEx@5, 5 clear to 20, 20Box Command@row1, column1 to row2, column 2Picture clausePICTURE clause is used to control of display or the information to be accepted.@.SAY.GETS PICTURE CODES:A-Allows only alphabets9-Allows only digits, signs for numeric dataN-Allows Letters and Digits#-Allows Only Digits, Blanks and SignsX-Allows any CharacterL-Allows any Logical Data T, t, F, f, Y, y, N, n

Y-Allows Only Y, y, N, n!-Converts letters into uppercase.*-Displays asterisk in place of leading zeros.,-Display the comma.-Display the decimal Point.Function ClauseYou can include the function clause, the picture clause or both to control how expr is displayed orprinted. A function clause affects the entire expression. It contains only the following function code.Function code & PurposeB Left – justifies numeric data within the display region.Example:ClearStore 2750 to num@5,20 say num@6,20 say num function “B”C Cr is displayed after a positive number to indicate a credit. Can be used with numeric data only.Example:ClearStore 15432.00 to amt@5,20 say amt@6,20 say amt function “c”D Uses the current set DATE format.Example:ClearStore 230801 to numStore “foxproprograming” to tit@5,20 say num function “D”@6,20 say tit function “D”E Edits date type data as British dateExample:ClearStore 230904 to num@6,20 say num function “E”T Trim leading and trailing blanks from expr

Example:Clear@5,20 ”fox” to tit@6,20 say tit function “T”X DB is displayed after negative numbers to indicate a debit. used only with numberic data.Example:ClearStore -15432.00 to amt@5,20 say amt@6,20 say amt function “X”Z expr is displayed as all blanks if its numericvalue is 0. used only with numeric data.Example:ClearStore o to amt@5,20 say amt@6,20 say amt function “z”( Encloses negative numbers in parentheses. Used only with numeric data.Example:ClearStore –755 to amt@5,20 say amt@6,20 say amt function “(“! Converts alphabetic characters to upper-case used with character data-onlyExample:ClearStore “foxpro programming” to tit@6,20 say tit function “!” Displays numeric data using scientific notation. Used with numeric data only.Example:ClearStore 75815 to amt@6,20 say amt function “ ”

Displays data in currently format. the currency symbol appears before or after the field valuedepending on the current setting of set currency. used with numeric data only.Example:ClearStore 75815 to amt@6,20 say amt function “ ”Picture expression can include the following characters:X Allows any character.Y Allows logical Y, y, N and n only. Converts y and n to Y and N, respectively.! Displays the current currency symbol specified by set currency. By default, the symbol is placedimmediately before or after the field.* Asterisks are displayed in front of the numeric value. Use with a dollar sign for check protection. A decimal point specifies the decimal point position., A comma is used to specifies digits to the left of the decimal point.Control StructuresIF statementIf Condition is True Executed and then False Not Executed.SyntaxIf (condition) thenStatement-1End ifExampleclearmark 0@5,5 say " Enter the Mark : " get mark RANGE 0,100ReadIf mark 40 Then@10,10 say " You have PASS"EndifIf .else .endif:The commands between if .end if will be executed only if condition is satisfied, otherwise the next

statement is executed. For every if there must be an end if. Every is matched with the nearestunmatched if.Syntax:If condition Command sequence-1 Else Command sequence-2 End ifCommand sequence –1 will be executed if a condition is true, if condition is false commandsequence-2 will be executed. Control falls to the next statement in either case, if program I still inexecution.Example 2clearStore 0 to x,y@5, 5 say " Enter the First value: " get x@7,5 say " Enter the Second value: " get yReadIF x y Then@10, 10 say str(x) “is Greater than” ltrim (str(y))Else@10, 10 say str(x) " is lesser than " ltrim (str(y))EndifExample 3clearStore space(1) to x,ch@5, 5 say " Enter any Alphabet: " get xReadch chr(asc(x) 32) && To convert Upper into LowerIF ch "a" .or. ch "e" .or. ch "i" .or. ch "o" .or. ch "u" then@10,10 say ch " is a VOWEL "Else@10,10 say ch " is a CONSONANT"Endif

NESTED IF: (IF within IF)clearstore 0 to x,y,z@5,5 say " Enter No1 : " get x@7,5 say " Enter No2 : " get y@9,5 say " Enter No3 : " get zReadIf x y thenIF x z then@ 15,5 say " X is Greater than y and z"Else@15,5 say "X is Greater than Y and Lesser than Z"EndifElseIF Y Z then@ 15,5 say " Y is Greater than X and Z"Else@15,5 say "Y is Greater than X but not Z"EndifEndifDO CASECase Commands are used to check for a specified conditionSyntax:DO CaseCase variable value Statement -1Case variable value Statement -2OtheriwseStatement -3End CaseExample:clearstore 0 to day

@5,5 say " Enter any number from 1 to 7 " get dayReadDO CASEcase day 1@10,10 say "SUNDAY"case day 2@10,10 say "MONDAY"case day 3@10,10 say "TUESDAY"case day 4@10,10 say "WEDNESDAY"case day 5@10,10 say "THURSDAY"case day 6@10,10 say "FRIDAY"case day 7@10,10 say "SATURDAY"OTHERWISE@10,10 SAy "Invalid Input"EndCaseFOR LOOP To repeatedly execute a series of lines in a Program. The lines of code b/w FOR and ENDOFR will be executed until the memoryfinal condition specified. Default STEP value is 1.SyntaxFOR memvar initial value TO final value STEP no .ENDFORExample: 1CLEARFOR I 1 TO 10variable is equal to the

?IEndForExample: 2To print the EVEN nos from 2 to 50CLEARFOR I 2 TO 50 STEP 2?IEndForCreating menu in Foxpro for DOS Posted on: 12 February 2012 By: KarthikeyanThis is an example of simple navigation menu programming in Foxpro 2.61. set talk off2. set stat off3. set scor off4. set cent on5. set date brit6. do whil .t.7.clea8.@5,20 to 19,45 doub9.@6,25 say "MAIN MENU"10.@7,21 to 7,44 doub11.k 012.@ 9,25 prompt "DATA ENTRY"13.@11,25 prompt "REPORT PRINTING"14.@13,25 prompt "PROCESS"15.@15,25 prompt "EXIT"16.@17,25 prompt "QUIT to SYSTEM"17.menu to k18.do case19.case k 120.do dataent21.case k 222.do repoprn23.case k 324.*do proces25.case k 426.exit27.case k 528.clos all29.clea all30.quit31.otherwise32.loop33.endcase34.enddo

85.86.87.88.89.90.91.clos allclea allproce dataentdo whil .t.clea@5,20 to 19,55 doub@6,30 say "DATA ENTRY MENU"@7,21 to 7

Foxpro for MS-DOS - Basic FoxPro 2.6 Commands FoxPro is SEMI-RDBMS Unlike other RDBMS systems, in FoxPro each database can contain only one table. Hence, the single table is called as database in this tutorial In FoxPro, first four characters of any command is enough to execute For e.g.:-