home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / T_LESSON.ZIP / TP-50A < prev    next >
Encoding:
Text File  |  1989-05-09  |  48.8 KB  |  1,256 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                                            
  10.  
  11.  
  12.                                            
  13.  
  14.  
  15.                                      TURBO-LESSONS
  16.  
  17.  
  18.                                 A TURBO Pascal Tutorial
  19.                           Version 5.0 (for TURBO Pascal 5.0)
  20.  
  21.  
  22.                                            
  23.  
  24.  
  25.  
  26.  
  27.  
  28.                                            
  29.  
  30.  
  31.                                            
  32.  
  33.  
  34.                                            
  35.  
  36.  
  37.                                            
  38.  
  39.  
  40.                                            
  41.  
  42.  
  43.                                            
  44.  
  45.  
  46.                                            
  47.  
  48.  
  49.                                  by Dr. Lyle M. Faurot
  50.                                       May 6, 1989
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.                 Copyright 1989 by Lyle M. Faurot.  All Rights Reserved.
  60.  
  61. î
  62.  
  63.  
  64.                          TURBO-LESSONS Registration Form
  65.  
  66.  
  67.  
  68.        Name____________________________________________  Date_____________
  69.  
  70.        Street_____________________________________________________________
  71.  
  72.        City________________________________ State_________ Zip____________
  73.  
  74.  
  75.        Would you like to receive notices about future releases
  76.        of Tutorials and other products?  Yes___ No___         [TP-5.0:R31]
  77.  
  78.  
  79.        Where did you get your copy of TURBO-LESSONS?______________________
  80.  
  81.  
  82.        Your vote counts!  Which of the following would you like next?
  83.  
  84.        _____ More TURBO-LESSONS for Turbo Pascal 5.0
  85.              (Several lessons of the next set are already in progress.)
  86.  
  87.        _____ TURBO-LESSONS for other programming languages
  88.  
  89.                Which ones? _______________________________________________
  90.  
  91.        _____ TURBO-LESSONS for spreadsheets, word processors, other products
  92.  
  93.                Which ones? _______________________________________________
  94.  
  95.                            _______________________________________________
  96.  
  97.  
  98.        Comments, Suggestions:
  99.  
  100.        -------------------------------------------------------------------
  101.  
  102.        -------------------------------------------------------------------
  103.  
  104.        -------------------------------------------------------------------
  105.  
  106.        -------------------------------------------------------------------
  107.  
  108.        -------------------------------------------------------------------
  109.  
  110.        ===================================================================
  111.  
  112.                         TURBO-LESSONS for Turbo Pascal 5.0
  113.                      Set 1: Lessons 1-16   $10.00 (U.S. Funds)
  114.  
  115.                    Mail to:  Dr. Lyle M. Faurot
  116.                              Box 494
  117.                              Moorhead, MN  56560
  118.  
  119. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  2
  120.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.                                    TABLE OF CONTENTS
  128.  
  129.               INTRODUCTION........................................   5
  130.  
  131.               OBJECTIVES..........................................   6
  132.  
  133.               SHAREWARE NOTICE....................................   7
  134.                   What is SHAREWARE?..............................   7
  135.                   How is TUTORIAL Shareware Different?............   7
  136.                   Try Before You Buy..............................   7
  137.                   Why Register Your Copy of TURBO-LESSONS?........   7
  138.                   How to Register.................................   8
  139.  
  140.               DISTRIBUTION OF TURBO-LESSONS.......................   9
  141.                   Copying and Sharing TURBO-LESSONS...............   9
  142.                   PC Clubs/Bulletin Boards........................   9
  143.                   PD/Shareware Disk Distribution Companies........   9
  144.                   TURBO-LESSON Files on the Distribution Diskette.  10
  145.  
  146.               TURBO-LESSON 1.  GETTING STARTED (Version 5.0)......  11
  147.                   How to Start and Stop Turbo.....................  11
  148.                   How to Switch and Zoom Windows..................  13
  149.                   How to Edit a File..............................  14
  150.                   How to Save a File..............................  14
  151.                   How to Display a Directory of Files.............  15
  152.                   How to Edit a Different File....................  16
  153.                   How to Recover a File Saved Earlier.............  17
  154.  
  155.               TURBO-LESSON 2.  ESSENTIAL EDITING SKILLS...........  19
  156.                   Moving the Cursor...............................  19
  157.                   Inserting and Replacing Text....................  20
  158.                   Deleting Text...................................  21
  159.                   Experimenting On Your Own.......................  22
  160.                   Saving and Retrieving Programs..................  22
  161.                   Re-Editing Each File............................  23
  162.                   Getting Up to Speed.............................  24
  163.  
  164.               TURBO-LESSON 3.  PROGRAM STRUCTURE..................  25
  165.                   Program structure...............................  25
  166.                   How to Compile a Program........................  26
  167.                   How to Run a Program............................  27
  168.                   Write and WriteLn statements....................  27
  169.                   Comments - at the beginning of program..........  30
  170.                   Comments - at the end of a statement line.......  31
  171.                   Comments - deactivate a section of code.........  31
  172.  
  173. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  3
  174.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  175.  
  176.  
  177.  
  178.           
  179.  
  180.  
  181.                              TABLE OF CONTENTS (continued)
  182.  
  183.               TURBO-LESSON 4.  DECLARATIONS, INPUT................  32
  184.                   The DECLARATIONS Part of a Program..............  32
  185.                   VAR Declaration.................................  32
  186.                   Input Using the ReadLn Statement................  33
  187.                   DEBUG - Tracing Statements......................  34
  188.                   DEBUG -  Watching Variables.....................  35
  189.                   Integer Variables...............................  36
  190.  
  191.               TURBO-LESSON 5.  INTEGER EXPRESSIONS................  37
  192.                   Assignment Statements...........................  37
  193.                   DEBUG -  Removing Watch Variables...............  38
  194.                   Integer Expressions.............................  38
  195.                   Problems with Expressions.......................  41
  196.  
  197.               TURBO-LESSON 6.  CONDITIONAL PROCESSING.............  43
  198.                   Selection Structures for Conditional Processing.  43
  199.                   DEBUG -  Goto Cursor............................  43
  200.                   IF Statement (Two-way Selection)................  44
  201.                   IF Statement (One-way Selection)................  45
  202.  
  203.               TURBO-LESSON 7.  REPEAT STATEMENT...................  48
  204.                   CHARacter Variables.............................  48
  205.                   BOOLEAN Variables...............................  49
  206.                   REPEAT Statement................................  50
  207.  
  208.               TURBO-LESSON 8.  CASE STATEMENT.....................  52
  209.                   Block Statement.................................  52
  210.                   CASE Statement..................................  55
  211.  
  212.               TURBO-LESSON 9.  FOR STATEMENT......................  57
  213.                   Controlling Field Width in Write Statements.....  57
  214.                   FOR Statement...................................  58
  215.  
  216.               TURBO-LESSON 10.  WHILE STATEMENT...................  60
  217.                   CONSTant Declaration............................  60
  218.                   WHILE Statement.................................  61
  219.                   Delay Timing Loop...............................  63
  220.  
  221.               TURBO-LESSON 11.  INTRODUCTION TO FUNCTIONS.........  65
  222.                   Pascal Subprograms..............................  65
  223.                   FUNCTION Declaration............................  66
  224.                   User-defined Function...........................  66
  225.                   Providing Input to the FUNCTION.................  67
  226.  
  227.               TURBO-LESSON 12.  A FUNCTION TO DETECT ERRORS.......  72
  228.                   Error Detection.................................  72
  229.                   Using a Predefined Function.....................  73
  230.                   Writing Your Own Function.......................  74
  231.  
  232. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  4
  233.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  234.  
  235.  
  236.  
  237.           
  238.  
  239.  
  240.                              TABLE OF CONTENTS (continued)
  241.  
  242.               TURBO-LESSON 13.  STRINGS...........................  76
  243.                   Strings.........................................  76
  244.                   String Replacement Statement....................  76
  245.                   Predefined String Function, LENGTH..............  78
  246.  
  247.               TURBO-LESSON 14.  INTRODUCTION TO PROCEDURES........  80
  248.                   PROCEDURE Declaration...........................  80
  249.                   Using a Procedure...............................  80
  250.                   Using Parameters................................  82
  251.                   A Counter with Error Checking...................  83
  252.  
  253.               TURBO-LESSON 15.  INTERACTIVE SCREEN HANDLING.......  85
  254.                   Setting up a Data Entry Screen..................  85
  255.                   Being Nice to Users - ClrScr....................  86
  256.                   Getting Around the Screen - GotoXY..............  86
  257.  
  258.               TURBO-LESSON 16.  REAL NUMBERS......................  88
  259.                   Range of Real Numbers...........................  88
  260.                   Input/Output of Real Numbers....................  88
  261.                   Calculations with Real Numbers..................  89
  262.                   Calculations with Integers and Real Numbers.....  91
  263.  
  264.               A CHALLENGE.........................................  92
  265.  
  266. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  5
  267.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  268.  
  269.  
  270.  
  271.           
  272.  
  273.           INTRODUCTION
  274.  
  275.                Since TURBO-LESSONS were first made available as Shareware in
  276.           1985, Pascal programmers around the world have provided
  277.           encouragement and some excellent suggestions for improving these
  278.           lessons.  I have used many of those suggestions in this update for
  279.           Turbo Pascal 5.0.
  280.  
  281.                The new DEBUG feature in 5.0 adds a terrific learning tool.
  282.           You will enjoy using the DEBUG "trace" and "watch" to explore the
  283.           workings of this programming language.
  284.  
  285.                Each TURBO-LESSON is a bite-size tutorial which introduces one
  286.           or more new concepts.  Each of the lessons are presented in the
  287.           same format which includes the OBJECTIVES of the lesson, and the
  288.           TUTORIAL portion of the lesson.  Most lessons direct you to work
  289.           with a sample program which is provided with these lessons.
  290.  
  291.                Be sure you make a back-up copy of the programs - you will be
  292.           modifying and adding to the sample programs, and may want to return
  293.           to the original unmodified copy of a program.
  294.  
  295.                Sample programs are numbered to correspond to the lessons--for
  296.           example, PROG3 goes with lesson 3.
  297.  
  298.                To begin, you should print the TURBO-LESSONS before loading
  299.           TURBO.  You may also want to print a copy of the programs.  This
  300.           will allow you to see the whole program.  The screen window often
  301.           limits your view to a small part of a program.
  302.  
  303. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  6
  304.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  305.  
  306.  
  307.  
  308.           
  309.  
  310.           OBJECTIVES
  311.  
  312.           The following objectives have guided the development of TURBO-
  313.           LESSONS.
  314.  
  315.           1.  TO HELP BEGINNING PROGRAMMERS
  316.  
  317.                Programmers who had difficulty learning Pascal from reference
  318.                books tell me they are able to make better progress on their
  319.                own after completing TURBO-LESSONS.
  320.  
  321.           2.  TO HELP YOU GET STARTED PROGRAMMING IN PASCAL
  322.  
  323.                We hope to provide the basics you need to get started with
  324.                Pascal and build your confidence and enthusiasm to continue
  325.                learning on your own.
  326.  
  327.           3.  TO PROVIDE PRACTICAL PROGRAMMING TECHNIQUES
  328.  
  329.                There is more to programming than just learning the elements
  330.                of the language.  The programming techniques you learn will
  331.                save you time and frustration in your future programming.
  332.  
  333.           4.  TO ENCOURAGE EXPERIMENTATION ON YOUR OWN
  334.  
  335.                Programming skill is acquired more by doing than by reading
  336.                about it.  The lessons are presented in a way designed to
  337.                challenge you to try things on your own.
  338.  
  339. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  7
  340.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  341.  
  342.  
  343.  
  344.           
  345.  
  346.           SHAREWARE NOTICE
  347.  
  348.  
  349.                                   What is SHAREWARE?
  350.  
  351.           SHAREWARE is a "Try Before You Buy" approach to marketing and
  352.           distribution of products.  Shareware is not free and it is not
  353.           public domain.  Shareware authors encourage users to copy and pass
  354.           on their copyrighted products.  If after trying out the product,
  355.           you continue using it, payment is expected.
  356.  
  357.  
  358.                          How is TUTORIAL Shareware Different?
  359.  
  360.           Most Shareware products are successful if you evaluate the product
  361.           and decide to continue using it.  Just the opposite is true of
  362.           Tutorial Shareware--it is successful if you don't need to continue
  363.           using it.
  364.  
  365.           The value of a good tutorial is in the "FIRST USE".  A successful
  366.           tutorial is like a newspaper--use it once and discard it.  (I hope
  367.           you won't discard TURBO-LESSONS though.  Give a copy to a friend.)
  368.  
  369.  
  370.                                   Try Before You Buy
  371.  
  372.           Let me suggest the following way to "Try Before You Buy" in the
  373.           special case of products which don't typically get "continued use."
  374.  
  375.                If you try the first few lessons and decide to continue, you
  376.                are expected to pay for the lessons.
  377.  
  378.           If the tutorials are successful, you are "continuing to use" the
  379.           skills and knowledge you received from the tutorials.
  380.  
  381.  
  382.                        Why Register Your Copy of TURBO-LESSONS?
  383.  
  384.           When you send your registration you:
  385.  
  386.                1.  Make it possible for the author to write more tutorials.
  387.  
  388.                2.  Help determine which tutorials will be written.
  389.  
  390.                3.  Find out about new products. The next set of TURBO-LESSONS
  391.                for Turbo Pascal 5.0 is already under construction!  These
  392.                lessons will feature data structures--Arrays, Records, Files.
  393.  
  394.                4.  Support SHAREWARE marketing.
  395.  
  396. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  8
  397.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  398.  
  399.  
  400.  
  401.           
  402.  
  403.  
  404.                                     How to Register
  405.  
  406.           The registration form is included with the first lesson file,
  407.           TP-50A.   The form is also stored in a file named REPLY.  To print
  408.           a copy of the form, type
  409.  
  410.                COPY REPLY PRN     or   COPY REPLY LPT1:
  411.  
  412.           When you complete the registration form, please include any
  413.           comments about the lessons.  This helps me improve the next version
  414.           or correct errors.
  415.  
  416.           Please use U.S. funds in payment.  It costs more than the price of
  417.           TURBO-LESSONS to collect checks from other countries.
  418.  
  419.           CANADIAN checks are not a problem.  My bank charges me $1.00 plus
  420.           the exchange rate.
  421.  
  422.           If for some reason the file, REPLY, is not with the set of TURBO-
  423.           LESSONS you receive, please let me know it is missing and where you
  424.           obtained TURBO-LESSONS so I can correct the problem.  You can  mail
  425.           your payment of $10.00 without the form to:
  426.  
  427.                Dr. Lyle M. Faurot
  428.                Box 494
  429.                Moorhead, MN  56560
  430.  
  431.           Thank you for supporting this product and the SHAREWARE marketing
  432.           concept.
  433.  
  434. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  9
  435.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  436.  
  437.  
  438.  
  439.           
  440.  
  441.           DISTRIBUTION OF TURBO-LESSONS
  442.  
  443.  
  444.                            Copying and Sharing TURBO-LESSONS
  445.  
  446.           You are encouraged to copy and share these lessons with others.
  447.           This is what makes shareware work--the author appreciates your help
  448.           in distributing this product.
  449.  
  450.           TURBO-LESSONS may be freely copied and shared.  TURBO-LESSONS may
  451.           not be sold.  PC Clubs and Disk Distribution companies may include
  452.           TURBO-LESSONS in their disk offerings provided any price charged is
  453.           based on the cost of disk and handling, and not on the contents of
  454.           the disk.
  455.  
  456.           TURBO-LESSONS must be distributed complete with all files.  A
  457.           complete list of files appears later in this section.
  458.  
  459.  
  460.                                PC Clubs/Bulletin Boards
  461.  
  462.           TURBO-LESSONS may be distributed by PC Clubs and uploaded to
  463.           Computer Bulletin Boards.  The set must be distributed complete
  464.           with all files provided.
  465.  
  466.  
  467.                        PD/Shareware Disk Distribution Companies
  468.  
  469.           Disk distribution companies may include TURBO-LESSONS in their
  470.           offerings provided they represent TURBO-LESSONS as SHAREWARE, not
  471.           Public Domain or Freeware.  Also the complete set of lessons and
  472.           files must be distributed together.
  473.  
  474.           Those who "buy" TURBO-LESSONS from disk companies should understand
  475.           that the author receives no royalty of any kind from these sales.
  476.           We are simply helping each other--I try to provide a quality
  477.           product for them to distribute, they provide publicity and
  478.           distribution which would otherwise be unavailable to me.
  479.  
  480.  
  481.                                     Site Licensing
  482.  
  483.           Schools, companies and other organizations are encouraged to write
  484.           for information about site licensing for multiple copies of TURBO-
  485.           LESSONS.
  486.  
  487. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  10
  488.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  489.  
  490.  
  491.  
  492.           
  493.  
  494.  
  495.                     TURBO-LESSON Files on the Distribution Diskette
  496.  
  497.           You should have received the following files with TURBO-LESSONS.
  498.           The approximate number of pages is listed to help you print the
  499.           lessons.
  500.  
  501.                File      Contents                        Pages to Print
  502.  
  503.                TP-50A    Lessons 1-2, Introduction,
  504.                          Table of Contents                       25
  505.                TP-50B    Lessons 3-6                             23
  506.                TP-50C    Lessons 7-11                            24
  507.                TP-50D    Lessons 12-16                           21
  508.                REPLY     Registration/Survey Form                 1
  509.                README    The starting point - read this first     1
  510.                PRINT.BAT To help you print the lessons
  511.                PROGx.PAS These are the programs, numbered to
  512.                          correspond to the lessons.  The following
  513.                          are included: PROG3.PAS, 4, 5, 6A, 6B, 6C,
  514.                          7, 8, 9, 10, 11, 11A, 12, 12A, 13, 13A, 14,
  515.                          14A, 15, 15A, 15B, 16, and TEST1.PAS.
  516.  
  517. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  11
  518.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  519.  
  520.  
  521.  
  522.           
  523.  
  524.           TURBO-LESSON 1.  GETTING STARTED (Version 5.0)
  525.  
  526.           OBJECTIVES - In lesson 1 you will learn how to:
  527.           
  528.           1.  Start and stop Turbo Pascal
  529.           2.  Switch windows
  530.           3.  Edit a file (programs are stored in files)
  531.           4.  Save a file
  532.           5.  Display a directory of files saved
  533.           6.  Edit a different file
  534.           7.  Recover a file saved earlier
  535.  
  536.           In lesson 1 you will learn to use the Turbo Pascal programming
  537.           environment.  Unlike many of the earlier programming language
  538.           systems, Turbo provides the various tools needed in one package.
  539.           This means you can quickly go from entering or correcting a program
  540.           to running and testing the program.  Turbo also speeds up debugging
  541.           of the program by "pointing" to your error with the cursor, and
  542.           indicating the nature of the problem.
  543.  
  544.           You will need the skills acquired in the first two lessons as you
  545.           work through later lessons.  If you find yourself unsure of some of
  546.           these file skills later, be sure to come back to lessons 1 and 2
  547.           for help.
  548.  
  549.  
  550.                             1.  How to Start and Stop Turbo
  551.  
  552.           To get started, put a diskette with Turbo Pascal in your disk
  553.           drive, or if you have Turbo Pascal on a hard disk, switch to the
  554.           subdirectory with Turbo.  The following files should be on the
  555.           diskette or hard drive:  Turbo.EXE, Turbo.TPL and Turbo.HLP.
  556.  
  557.           ##### DO:
  558.  
  559.           Type Turbo then press the Enter key to start Turbo Pascal.
  560.  
  561.           The screen which appears has the following across the top:
  562.  
  563.                File  Edit  Run  Compile  Options  Debug  Break/watch
  564.  
  565.           This is the main menu of Turbo Pascal.  In this lesson you will
  566.           explore only the first two options:  File and Edit.
  567.  
  568.           Notice the first letter of each word is highlighted.  You can
  569.           choose any of the menu options by typing the first letter of the
  570.           option while holding down the Alt key.
  571.  
  572.           If the first letter of each word doesn't appear highlighted, try
  573.           adjusting the contrast and brightness controls of your computer
  574.           monitor.
  575.  
  576. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  12
  577.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  578.  
  579.  
  580.  
  581.           To choose the File option, you would hold down the Alt key and type
  582.           F.
  583.  
  584.           ##### DO:
  585.  
  586.           Type Alt-F (hold down the Alt key while you type F) to choose the
  587.           File option.
  588.  
  589.           The window which appeared under File shows what you can do with
  590.           files:  Load a file, start a New file, Save a file, display a
  591.           Directory of files saved, Quit Turbo Pascal, and several other
  592.           choices.
  593.  
  594.           You have started Turbo--next you will need to know how to stop it.
  595.           The Quit option lets you exit the Turbo programming environment.
  596.  
  597.           ##### DO:
  598.  
  599.           Type Q to leave Turbo.
  600.  
  601.           Try starting Turbo again and learn another way to use the menu.
  602.  
  603.           ##### DO:
  604.  
  605.           Type Turbo and press the Enter key to start Turbo.
  606.  
  607.           Notice the way one of the menu options is highlighted.
  608.  
  609.           ##### DO:
  610.  
  611.           Press the right arrow key several times.  The highlight should move
  612.           from one menu option to the next.  Also try the left arrow.  (If
  613.           nothing happens, check for NUM at the lower right of the screen.
  614.           If the word NUM appears, press the Num Lock Key--NUM will
  615.           disappear.  Now the arrow keys should work.)
  616.  
  617.           You chose the File option from the menu before by typing Alt-F.
  618.           There's another way to choose an option--you can move the highlight
  619.           to the option you want and press the Enter key.
  620.  
  621.           ##### DO:
  622.  
  623.           Move the highlight to the File option and press Enter.
  624.  
  625.           ##### DO:
  626.  
  627.           In the window of choices under File, use the down arrow key to move
  628.           the highlight to Quit, then press Enter.
  629.  
  630.           NOTE:  An option selected by typing the first letter is carried out
  631.           immediately without pressing the Enter key.  An option selected by
  632.           moving the highlight to the desired option must be activated by
  633.           pressing the Enter key.
  634.  
  635. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  13
  636.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  637.  
  638.  
  639.  
  640.           ##### DO:
  641.  
  642.           Try starting and stopping Turbo several times using both ways to
  643.           choose File and Quit.
  644.  
  645.  
  646.                           2.  How to Switch and Zoom Windows
  647.  
  648.           There are two windows on the screen, the top one labelled Edit and
  649.           the lower one Watch or Output.  The Edit window is used for
  650.           entering and editing programs.  The Watch window is used with the
  651.           DEBUG features in the lessons that follow.  The Output window is
  652.           used to display output when you run your programs.  Switching the
  653.           lower window between Watch and Output is covered in a later lesson.
  654.  
  655.           Only one of the two windows is active at any time.  The active
  656.           window has a double line at the top and the label is highlighted.
  657.  
  658.           ##### DO:
  659.  
  660.           Press F6 several times, noting the effect on the windows.
  661.  
  662.           F6 lets you switch between windows.
  663.  
  664.           Messages at the bottom of the screen show you the effect of special
  665.           keys which are active with each window.
  666.  
  667.           ##### DO:
  668.  
  669.           Watch the messages at the bottom of the screen while you press F6
  670.           several times.
  671.  
  672.           Did you see how the F6 message changed?  When the Edit screen is
  673.           active, the message F6-Output tells you that pressing F6 will
  674.           switch to the Output window.  When the Output window is active,
  675.           F6-Edit prompts you to press F6 to switch to the Edit window.
  676.  
  677.           The messages at the bottom of the screen will help you find your
  678.           way around while you get acquainted with Turbo Pascal.
  679.  
  680.           One of the messages is F5-Zoom.
  681.  
  682.           F5 switches the active window between a full screen display and a
  683.           partial screen display.  Sometimes you want to see both windows,
  684.           sometimes just one window expanded to fill the full screen.
  685.  
  686.           ##### DO:
  687.  
  688.           Press F5 several times.
  689.  
  690.           ##### DO:
  691.  
  692.           Use F6 to switch to the other window, then press F5 several times.
  693.  
  694. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  14
  695.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  696.  
  697.  
  698.  
  699.           This feature is handy when you would like the full screen for
  700.           editing a program or when you want to see program output displayed
  701.           on the full screen.
  702.  
  703.           To make it easier to see the features of the editor without the
  704.           Output window, we will use the full screen Edit window to explore
  705.           how to edit a file.
  706.  
  707.  
  708.                                 3.  How to Edit a File
  709.  
  710.           Why do you need to know how to edit a file?
  711.  
  712.           Programs are stored in files.  Before you can run a program you
  713.           must type the program into a file.  You also use the editor to
  714.           correct mistakes in the program.
  715.  
  716.           You will learn more of the details of editing a file later.  Here
  717.           you will type a short sentence to be stored in the Editor Work
  718.           file.  Later you will use the editor to type in programs.
  719.  
  720.           NOTE:  Editor Work file here refers to the file you are currently
  721.           editing.  Earlier versions of Turbo Pascal referred to this file as
  722.           the Work file;  Starting with version 4.0, this file is called the
  723.           Editor file.  I refer to this file as the Editor Work file
  724.           throughout these lessons.
  725.  
  726.  
  727.           ##### DO:
  728.  
  729.           If the Edit window is not the active one, use F6 to switch to it.
  730.           Then use F5 to "Zoom" the Edit window to full screen size.
  731.           (Remember, the active window is marked with a double line at the
  732.           top.)
  733.  
  734.           The blinking cursor should be at the upper left corner of the edit
  735.           window.
  736.  
  737.           ##### DO:
  738.  
  739.           Type the sentence:  This is in a file named ONE.
  740.  
  741.           In the next section you will Save this file and in a later section
  742.           Load it back into the Edit Work file again.
  743.  
  744.  
  745.                                 4.  How to Save a File
  746.  
  747.           Why do you need to know how to save a file?
  748.  
  749.           When you edit a program, it is in the computer memory.  When you
  750.           turn the computer off or leave the Turbo Pascal programming
  751.           environment you will lose the program in the computer's memory.  To
  752.           preserve the program for future use, you must save the program as a
  753.  
  754. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  15
  755.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  756.  
  757.  
  758.  
  759.           file on diskette or hard disk.  Saving a program means making a
  760.           copy of the program which is currently in the Editor Work file and
  761.           placing that copy on a disk.
  762.  
  763.           The Save choice in the File menu window is used to store the
  764.           current Editor Work file on diskette or hard disk.
  765.  
  766.           ##### DO:
  767.  
  768.           Choose the File option (type Alt-F), type S to Save the file you
  769.           just entered.
  770.  
  771.           Notice that you could use the arrow keys to move the highlight to
  772.           Save instead of typing S.  Remember to use the Enter key to
  773.           activate the highlighted option.  If you just type S no Enter is
  774.           required.  You will soon form the habit of using the menu technique
  775.           you find best for you.
  776.  
  777.           Look at the status line at the top of the screen--the name of your
  778.           file is NONAME.PAS.  This is the name Turbo gives your file until
  779.           you rename it something else.  The first time you save your file
  780.           you are reminded to rename it.
  781.  
  782.           ##### DO:
  783.  
  784.           At the rename prompt type ONE as the new name for your file.  Press
  785.           the Enter key.  (If you already have a file named ONE.PAS on the
  786.           disk, you will be prompted for permission to overwrite the old
  787.           ONE.PAS.)
  788.  
  789.           NOTE:  You could type ONE.PAS instead of ONE, but it's not
  790.           necessary.  PAS will be added as the file extension anytime you
  791.           omit the extension.
  792.  
  793.  
  794.           Your Editor Work file has been stored on the disk with a name of
  795.           ONE.PAS.  When you need to recover this file, you can get it back
  796.           with the Load choice in the File menu window.  You will do that in
  797.           a bit, but first, let's see how to find out which files are on your
  798.           disk.
  799.  
  800.  
  801.                         5.  How to Display a Directory of Files
  802.  
  803.           After you have saved a few files you may forget their names or
  804.           forget which ones you have on your disk.  The Directory choice in
  805.           the File menu window helps you list your disk files.
  806.  
  807.           ##### DO:
  808.  
  809.           Get the File menu window and type D to display a directory.
  810.  
  811.           Did you get a directory?
  812.  
  813. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  16
  814.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  815.  
  816.  
  817.  
  818.           First, Turbo gives you a choice.  Do you want to list all files
  819.           (*.*) or files with a file extension of PAS (*.PAS) or maybe files
  820.           that start with the letter S (S*.*)?  Please check your operating
  821.           system manual if you need more help with the meaning of the
  822.           asterisk (*) in selecting groups of files to display.
  823.  
  824.           Turbo suggests the choice, *.*, to display all files.
  825.  
  826.           ##### DO:
  827.  
  828.           At the Enter Mask prompt, *.*, press the Enter key.
  829.  
  830.           You should see a list of all your files on the screen.
  831.  
  832.           The Esc key is used to back up to a previous of the menu.  While
  833.           your directory is displayed you can return to the Directory choice
  834.           in the File window by pressing the Esc key.
  835.  
  836.           ##### DO:
  837.  
  838.           Press Esc to back-up to the Directory choice.
  839.  
  840.           The F10 key provides another way to exit the directory display.
  841.           Pressing F10 will take you back to the main menu.  Both the
  842.           directory display and the File window will disappear.
  843.  
  844.           ##### DO:
  845.  
  846.           Display the directory again.  Then use F10 to return to the main
  847.           menu.
  848.  
  849.           F10 will take you back to the main menu from almost anywhere in the
  850.           Turbo programming environment.
  851.  
  852.  
  853.                            6.  How to Edit a Different File
  854.  
  855.           Under the File option, the New choice allows you to establish a new
  856.           file.  Since there can only be one Editor Work file in computer
  857.           memory at one time, the current Editor Work file will be removed
  858.           from memory before starting the new file.  If you haven't saved the
  859.           current Editor Work file since it was last changed, you will be
  860.           prompted to save it before establishing a new Editor Work file.
  861.  
  862.           ##### DO:
  863.  
  864.           Choose New in the File menu window.
  865.  
  866.           If you are prompted to save the current file, type Y.
  867.  
  868.           The blinking cursor should be at the upper left of the edit window.
  869.           This indicates the editor is ready to use.
  870.  
  871. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  17
  872.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  873.  
  874.  
  875.  
  876.           ##### DO:
  877.  
  878.           Type:  This is in file TWO.
  879.  
  880.           ##### DO:
  881.  
  882.           Save the Editor Work file.  Name it TWO.
  883.  
  884.  
  885.                         7.  How to Recover a File Saved Earlier
  886.  
  887.           You have two files saved on the disk:  ONE.PAS and TWO.PAS.
  888.           TWO.PAS is also in the Editor Work file.  If you wanted to get
  889.           ONE.PAS back for further editing you would use the Load choice in
  890.           the File menu window.
  891.  
  892.           ##### DO:
  893.  
  894.           Get the File menu window and type L to load a file.
  895.  
  896.           Turbo prompts you for Load File Name.
  897.  
  898.           
  899.  
  900.           ##### DO:
  901.  
  902.           Type ONE and press Enter.
  903.  
  904.           Notice the name of the file in the status line at the top of the
  905.           screen.  It should be ONE.PAS.
  906.  
  907.           There's another way to select the file to load into the Editor Work
  908.           file.  This method allows you to select the desired file from a
  909.           menu.  Load the file named TWO.PAS again using the load menu.
  910.  
  911.           ##### DO:
  912.  
  913.           Get the File menu window and press L to Load a file.
  914.  
  915.           ##### DO:
  916.  
  917.           When the Load File Name prompt appears type *.PAS and press the
  918.           Enter key.  (*.PAS may already be in the prompt box.  Then you
  919.           would only need to press the Enter key.)
  920.  
  921.           All files with a PAS extension should be displayed.  You can use
  922.           the arrow keys to move the highlight to the file you want to load.
  923.           When the desired file is highlighted, press the Enter key to load
  924.           the file.
  925.  
  926.           ##### DO:
  927.  
  928.           Use the arrow keys to move the highlight to the file, TWO.PAS.
  929.           Press the Enter key.
  930.  
  931. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  18
  932.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  933.  
  934.  
  935.  
  936.           Check the status line to verify that file TWO.PAS is in the Editor
  937.           Work file.
  938.  
  939. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  19
  940.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  941.  
  942.  
  943.  
  944.           
  945.  
  946.           TURBO-LESSON 2.  ESSENTIAL EDITING SKILLS
  947.  
  948.           OBJECTIVES - In lesson 2 you will develop skill in:
  949.  
  950.           1.   Moving the Cursor
  951.           2.   Inserting and Replacing Text
  952.           3.   Deleting Text
  953.           4.   Efficiently Editing and Re-editing Files
  954.  
  955.           In the previous lesson you began your editing skills by entering a
  956.           short sentence into a file and saving that file.  In this lesson
  957.           you will learn to get around the file by moving the cursor and to
  958.           add, change, or delete text in the file.
  959.  
  960.  
  961.                                  1.  Moving the Cursor
  962.  
  963.           To see how to move the cursor around you need several lines of text
  964.           in your Editor Work file.  Then you can try moving the cursor to
  965.           see how the different keys work.
  966.  
  967.           NOTE:  The Pascal programs supplied with these lessons are in files
  968.           named PROG3.PAS, PROG4.PAS, etc.  Sometimes you will need to create
  969.           and name your own files for storing programs.  I will simply
  970.           suggest a file name to use when a DO section directs you to create
  971.           a new file.  In Turbo version 5.0 you don't supply the file name
  972.           until the first time you save the file.  I suggest you name the
  973.           file immediately whether the version requires it or not, so that
  974.           the file name always appears in the status line at the top of the
  975.           Edit screen.  You can save an "empty" file in 5.0 so you could save
  976.           and name a file before editing it.
  977.  
  978.  
  979.           ##### DO:
  980.  
  981.           Start a new file using the New option in the File menu box.
  982.  
  983.           ##### DO:
  984.  
  985.           Type the following lines into your Editor Work file. (Suggested
  986.           file name:  SKILLS.)
  987.  
  988.                This is not a program.
  989.                This is only to seeee how teh editttor works.
  990.                You can type whatever you want.
  991.  
  992.           Notice the status line on the top of the screen as you type.  It
  993.           lets you know the line and column of the cursor's position.  To
  994.           move around the screen easily, use the arrow keys at the right of
  995.           the keyboard to move the cursor.  If your keyboard doesn't have
  996.           arrow keys, note that the following may be substituted for the
  997.           arrow keys:
  998.  
  999. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  20
  1000.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  1001.  
  1002.  
  1003.  
  1004.           
  1005.                Ctrl-s = left-arrow
  1006.                Ctrl-d = right-arrow
  1007.                Ctrl-e = up-arrow
  1008.                Ctrl-x = down-arrow
  1009.  
  1010.           ##### DO:
  1011.  
  1012.           Try out the arrow keys.  The left and right arrows move the cursor
  1013.           one character to the left or right, and the up and down arrows move
  1014.           the cursor one line up or down, as long as there is something typed
  1015.           there.
  1016.  
  1017.           ##### DO:
  1018.  
  1019.           To move a little faster, try Ctrl-left-arrow.  It moves the cursor
  1020.           one word to the left.  Ctrl-right-arrow moves one word to the
  1021.           right.  (Ctrl-A = Ctrl-left-arrow, Ctrl-F = Ctrl-right-arrow.)
  1022.  
  1023.           ##### DO:
  1024.  
  1025.           Try some of the other cursor movement keys.  Home takes you to the
  1026.           beginning (left) of the current line, while End moves the cursor to
  1027.           the end of the current line.  Ctrl-Home moves the cursor to the top
  1028.           of the current screen, while Ctrl-End moves the cursor to the
  1029.           bottom of the current screen.
  1030.  
  1031.           Two other keys that are useful if your program is longer and will
  1032.           not all fit on one screen are the PgUp and PgDn keys.  They move
  1033.           the cursor to the previous or next screen respectively.  Also,
  1034.           Ctrl-PgUp moves to the very beginning of the file, while Ctrl-PgDn
  1035.           moves to the end of the file.  (With only a few practice lines in
  1036.           your Work file, you may not see the benefit of these keys.
  1037.           Remember to try these combinations later when you are working with
  1038.           larger files.)
  1039.  
  1040.  
  1041.                            2.  Inserting and Replacing Text
  1042.  
  1043.           There are two ways to type text when using an editor or word
  1044.           processor:
  1045.  
  1046.           
  1047.                1.   Insert new text while pushing existing text to the right
  1048.                     to make room for the new text, and
  1049.                
  1050.                2.   Overwrite text by typing over the original text. (You may
  1051.                     know this as the "Replace" mode or "Typeover" mode if you
  1052.                     use other editors or word processors.)
  1053.  
  1054.           ##### DO
  1055.  
  1056.           Look at the top line of the screen while depressing the Ins key
  1057.           several times.  The status line indicates whether "Insert" or
  1058.  
  1059. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  21
  1060.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  1061.  
  1062.  
  1063.  
  1064.           "Overwrite" mode is presently active.  The Ins key is the way to
  1065.           switch between modes.
  1066.  
  1067.           ##### DO:
  1068.  
  1069.           Try using both modes on the text.  Type this sentence:
  1070.           
  1071.                Today is a nice day.
  1072.           
  1073.           Change it to say it is a nice sunny day.  The easiest way to do
  1074.           that (adding a new word) is to use insert mode.  The text is
  1075.           inserted to the left of the cursor.
  1076.           
  1077.           Change sunny to rainy.  The quickest way to do this is to use
  1078.           overwrite mode, since you want to replace one word with another.
  1079.  
  1080.           A very significant difference between Insert and Overwrite mode is
  1081.           the way the Enter key works in the two modes.  With the editor in
  1082.           the insert mode, you can use the Enter key to open up new blank
  1083.           lines for inserting new lines of text or program.  This doesn't
  1084.           work in the overwrite mode.
  1085.  
  1086.           ##### DO:
  1087.  
  1088.           Use the Ins key to put the editor in the Overwrite mode.
  1089.  
  1090.           Place the cursor at the beginning of one of your lines of text.
  1091.  
  1092.           Press the Enter key several times.  What happens?
  1093.  
  1094.           ##### DO:
  1095.  
  1096.           Put the editor in the Insert mode.
  1097.  
  1098.           Press the Enter key several times.  What results does this produce?
  1099.  
  1100.           REMEMBER THIS WHEN THE ENTER KEY DOESN'T SEEM TO WORK RIGHT!
  1101.  
  1102.  
  1103.                                    3.  Deleting Text
  1104.  
  1105.           There are several ways to delete text:
  1106.                
  1107.                1.   The Del key (or Ctrl-G) deletes the character at the
  1108.                     cursor position and pulls the characters from the right.
  1109.                     You might think of this as "eating" the characters to the
  1110.                     right.
  1111.                
  1112.                2.   The backspace key (or Ctrl-H) deletes the character to
  1113.                     the left of the cursor and pulls the characters from the
  1114.                     right.  This "eats" characters to the left.  Note that
  1115.                     this is not the same action as the left arrow key which
  1116.                     moves the cursor left without deleting characters.
  1117.                
  1118.  
  1119. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  22
  1120.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  1121.  
  1122.  
  1123.  
  1124.                3.   Ctrl-Y deletes the entire line that the cursor is on.
  1125.                     The previous two ways to delete just delete one character
  1126.                     at a time while Ctrl-Y gives you a way to delete a whole
  1127.                     line at a time.  (Remember, the Enter key will open up a
  1128.                     blank line when the editor is in the insert mode.  Ctrl-Y
  1129.                     doesn't leave a blank line where a line is deleted.)
  1130.  
  1131.           ##### DO:
  1132.  
  1133.           Try correcting the mistakes in your file by deleting mistakes and
  1134.           correcting them with either insert or overwrite.  Type in more
  1135.           sentences with mistakes and try different ways to correct them to
  1136.           see for yourself how these different techniques work.  Try deleting
  1137.           a whole line.
  1138.  
  1139.           You have tried the basics of entering and editing your program.
  1140.           Learning these now will save time and frustration later when you
  1141.           are working on programs!  So if you are unsure how some of these
  1142.           work, go back and experiment with them until you are comfortable
  1143.           with the basic editing features.
  1144.  
  1145.           NOTE: THE REMAINDER OF LESSON 2 IS INTENDED TO HELP YOU GET "UP TO
  1146.           SPEED" USING THE TURBO PROGRAMMING ENVIRONMENT.  THE EDITING AND
  1147.           FILE HANDLING SKILLS YOU DEVELOP NOW WILL SAVE TIME AND FRUSTRATION
  1148.           IN LATER LESSONS.
  1149.  
  1150.  
  1151.  
  1152.                              4.  Experimenting On Your Own
  1153.  
  1154.           In the next lesson you will begin writing Pascal programs.  How
  1155.           well you learn to program in Pascal will be determined by how well
  1156.           you teach yourself.  Programming is learned best by programming,
  1157.           experimenting, trying things on your own.  The ##### DO sections in
  1158.           these lessons are only intended to get you started.  When you do
  1159.           the activities suggested, you will probably get ideas for other
  1160.           things to try.  You should pursue your ideas--try to expand on the
  1161.           programs provided.
  1162.  
  1163.           The biggest obstacle to experimentation is the fear of "messing up"
  1164.           the program that is being built by the DO sections.  The main
  1165.           purpose here is to provide enough practice SAVING and RETRIEVING a
  1166.           program so that you will have no fear of losing the "official"
  1167.           program while experimenting with programs of your own.
  1168.  
  1169.  
  1170.                           5.  Saving and Retrieving Programs
  1171.  
  1172.           Because there is only one Editor Work file in the computer's memory
  1173.           at any one time, you need to be able to quickly save a file so you
  1174.           can experiment with a different one.  When you are through
  1175.           experimenting, you can easily retrieve the program you were
  1176.           previously editing.
  1177.  
  1178. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  23
  1179.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  1180.  
  1181.  
  1182.  
  1183.           Turbo makes it very easy to save your programs.  Turbo will remind
  1184.           you to save your program if you are about to do something that
  1185.           would erase it.  However, it is up to you to be sure your program
  1186.           is saved.
  1187.  
  1188.           To develop facility saving and retrieving files, you will edit and
  1189.           re-edit files named ONE, TWO, THREE, FOUR, and FIVE.  You already
  1190.           have files named ONE and TWO.  You will first add files THREE,
  1191.           FOUR, and FIVE with a short sentence in each.  Then you will edit
  1192.           each file again to add your first name as the second line of each
  1193.           file.  Finally, you will edit each file again, adding your last
  1194.           name.  If you time yourself as you edit each of the five files the
  1195.           last time you may be surprised at how quickly you can carry out
  1196.           these essential file operations.
  1197.  
  1198.           ##### DO:
  1199.  
  1200.           Start a new file.
  1201.  
  1202.           ##### DO:
  1203.  
  1204.           Type:  This is in file THREE.
  1205.  
  1206.           Save this file with the file name THREE.
  1207.  
  1208.           ##### DO:
  1209.  
  1210.           Create and save files FOUR and FIVE with the messages:
  1211.                This is in file FOUR and This is in file FIVE.
  1212.  
  1213.           If you have trouble with these steps, please refer back to
  1214.           lesson 1.
  1215.  
  1216.  
  1217.                                6.  Re-Editing Each File
  1218.  
  1219.           At this point you will add a line with your first name to each
  1220.           file.  Remember to use the Insert mode to enter the additional
  1221.           line.
  1222.  
  1223.           ##### DO:
  1224.  
  1225.           Load file ONE.  Edit the file to add your first name as a second
  1226.           line of the file.  To position the cursor at the beginning of a new
  1227.           line, first move it to the end of the existing line and press the
  1228.           enter key.  (The editor must be in Insert mode).
  1229.  
  1230.           Save the file.
  1231.  
  1232.           ##### DO:
  1233.  
  1234.           Do the same Load, Edit, Save to add your first name to each of the
  1235.           other files.
  1236.  
  1237. î        TURBO-LESSONS - A Pascal Tutorial       Version 5.0        Page  24
  1238.             Copyright 1989  Lyle M. Faurot      Lessons 1-16: $10.00
  1239.  
  1240.  
  1241.  
  1242.                                 7.  Getting Up to Speed
  1243.  
  1244.           As you edit the files one final time to add your last name,  you
  1245.           might want to time yourself--you are getting pretty good at this by
  1246.           now!
  1247.  
  1248.           ##### DO:
  1249.  
  1250.           Add your last name following your first name in each of the files.
  1251.  
  1252.           That didn't take long, did it?
  1253.  
  1254.           REMEMBER:  IN THE LESSONS THAT FOLLOW, IT'S QUITE EASY TO SAVE A
  1255.           PROGRAM, SO YOU CAN EXPERIMENT WITH YOUR OWN IDEAS.
  1256.