1  Introduction

Automating Memo Entry

Mark Ruth and Joe Van Dertol

With the release of the dBASE IV product, memo field  features have
been greatly improved.  One of these features is the  ability to
display the contents of a memo field in a window.  By pressing 
Ctrl-Home you can then enter the memo for editing.



2  Article

The following method uses a keyboard macro containing the keystroke 
{Ctrl-Home} to provide automatic access to the memo field.  When the 
cursor is placed on the memo field window the keyboard macro executes 
a Ctrl-Home allowing automatic access to the memo field.  Since  a
keyboard macro is used in the program this concept cannot be applied 
to .FMT files and the EDIT or APPEND commands.  Also, the width of 
the window is smaller than that of the memo text editor, therefore  it
is possible that all of the text may not be displayed on the screen.

The steps needed to implement this objective follow below.

Creating a keyboard macro

1.      Create a keyboard macro containing the  keystroke Ctrl-Home. A
keyboard macro is a file that stores keystrokes.  They are usually 
used to automate repetitive tasks.  Rather than typing the keystrokes 
again and again the user "plays" the macro containing the keystrokes. 
To create a keyboard macro from the Control Center

a       Press Alt-T  to open the Tools menu. b. Highlight Macros and
press Return.

c.      Highlight Begin Recording and press Return.

d.      Type A.  You could use another letter if  A is already being
used.

e.      Press Ctrl-Home.

f.      Press F10 to access the Tools menu.

g.      Highlight Macros and press Return.

h.      Highlight End Recording and press Return.

 

Edit the macro

2.      Edit the macro so that it contains only {Ctrl-Home}. This
macro will be called within the QMemo.PRG program to access the  memo
field and therefore needs only to contain {Ctrl-Home}.  To eliminate
any unwanted keystrokes

a.      Press Atl-T and type M to select Modify  from the Tools menu.

b.      Type your macro name  (for example, A). You should now see the
following on your screen:

       {Ctrl-Home}{F10}{Enter}{Enter}

c.      Edit out everything except the {Ctrl-Home}.

d.      Press Ctrl-End to exit editor.

e.      Type S to select Save Library. 

f.      Type MEMOS to save the macro to a file called  Memos.KEY. This
step is necessary to permanently store your macro so it may be  reused
later.  You can save many more macros with different names  to this
file.  For further information about creating and using macros  see
Using the Menu System 13-2.

3.       The next step is to create a program that will  open the file
that you wish to edit, paint the screen, control the  movement through
the file, and provide a way to exit.  With the exception  of the memo
field these functions are relatively easy to code, however  the use of
the keyboard macro and the memo field in a window requires  some
additional considerations:

a.      A keyboard macro will execute only when the program  calls for
input from the keyboard.  This restriction requires that  the PLAY
MACRO command come before a READ.  If the command is placed  after a
READ it will wait to execute until a later READ.  This will  cause
some very unpredictable results.

b.      The macro must affect only the memo field.



In order for the macro to affect only the memo field it must have  its
own READ command.  Having two READ statements on one screen will 
affect cursor movement and the display of the memo field data. 
First,  advancing  beyond the first READ would force a READ of the
memo field.  You would  not be able to advance past the memo without
having to enter it first.  You  would then need to press Ctrl-End and
Return on every  record to get out of the memo and move on to the next
record even  if you did not want to see the memo.  To provide for
smooth movement  and viewing of the data from one record to the next,
and allow you  to bypass entering the memo field, the READ for the
memo is placed  inside an IF...ENDIF which tests the last key pressed.

Since the memo field window follows a READ command, contents of the 
window will not display until the READ for the memo field is
executed.  Memo  fields cannot be displayed in a window with a SAY
command. To display  the data in the memo field window it must be
opened with a GET command  followed by a CLEAR GETS command.  The
CLEAR GETS command is necessary  so the memo field is not read with
the other fields on the screen.

Sample code showing these ideas follows.  The program will allow you 
to edit an existing data file.  It  can also be used to add new
records  (with some modification). 

Notes

We haven't discussed getting out of a memo field  edit because there
is really no short cut.  Although we could create  a keyboard macro
that would press Ctrl-End to leave the memo  field, you'd have to
invoke the macro manually by hitting a two-key  combination.  The only
advantage would be that the key combination  might be easier to
remember for someone who isn't familiar with the  dBASE keystrokes.

When entering the memo field the ruler, status bar, and  menu will
appear; there is no way to suppress them.

The dBASE editor has a line length (memo width) of 65 characters. 
Unless  you are using an external editor, or you like scrolling, make
sure  that your memo window is at least 65 characters wide. 

The window will take precedence over the coordiantes given with the
@...GET...OPEN WINDOW command.  Any valid screen coordinates are
acceptable and will not change the position of the window.





3  Sample DBF Structure

Employee.DBF



Structure for database: C:\FILES\EMPLOYEE.DBF
Number of data records:     141
Date of last update   : 12/23/88
Field  Field Name  Type      Width Dec Index
    1  ID          Character    5          N
    2  LNAME       Character   20           N
    3  FNAME       Character   15           N
    4  ADDRESS     Character   25           N
    5  CITY        Character   20           N
    6  STATE       Character    2           N
    7  ZIP         Character    5           N
    8  HIREDATE    Date         8           N
    9  SALARY      Numeric      9   2       Y
   10  EX_NONEX    Logical      1           N
   11  COMMENTS    Memo        10           N
** Total **                    121 



4  Sample Program: QMemo

QMemo.PRG

*--- QMemo
*--- Sample program to demonstrate the use of memo fields.
*--- Mark Ruth & Joe Van Dertol
*--- Data file: Employee.DBF
*--- Indexes:   none

*--- SET ENVIRONMENT
SET SCOREBOARD OFF
SET CONFIRM ON
SET STATUS OFF
SET TALK OFF
SET BELL OFF

*--- CREATE MEMORY VARIABLES
quitedit = .F.
enterkey = 13
dnarrow  = 24
uparrow  =  5
pgup     = 18
esc      = 27

DEFINE WINDOW wndow1 FROM 13, 5 TO 19,74

*--- Open data files and restore macro
USE Employee
RESTORE MACROS FROM Memo          && Needed to recall macro into
memory

*--- Execute commands while quitedit is FALSE
DO WHILE .NOT. quitedit
        
        *--- Open window to display memo
        @ 13, 5 GET comments OPEN WINDOW Wndow1 
        CLEAR GETS

        @  1, 3 TO 20,76 DOUBLE 
        @  2,26 SAY "EMPLOYEE FILE FORM" 
        @  3,26 SAY REPL(CHR(196),18)
        @ 21, 3 TO 23,76 DOUBLE
        @ 22, 8 SAY "PgUp/PgDn Up/Down a record -- " ;
          + "Uparrow/Downarrow Up/Down a field"

        @  4, 6 SAY "ID:" GET Id PICTURE "99999" 
        @  4,40 SAY "Record Number: " + STR(RECNO(),6)
        @  6, 6 SAY "Last Name:" GET Lname PICTURE
"XXXXXXXXXXXXXXXXXXXX" 
        @  6,40 SAY "First Name:" GET Fname PICTURE "XXXXXXXXXXXXXXX" 
        @  8, 8 SAY "Address: " GET Address PICTURE
"XXXXXXXXXXXXXXXXXXXXXXXXX" 
        @ 10,11 SAY "City:" GET City PICTURE "XXXXXXXXXXXXXXXXXXXX" 
        @ 10,39 SAY "State:" GET State PICTURE "XX" 
        @ 10,56 SAY "Zip:" GET Zip PICTURE "XXXXX" 
        @ 12, 6 SAY "Comments:"
        READ     && First READ
        
        lkey = LASTKEY()
        
        DO CASE
                CASE lkey = enterkey .OR. lkey = dnarrow
                        *--- Test for return or down arrow
                        @ 12,20 SAY "(CTRL-END or ESC to exit)"
                        *--- Clear the bottom box area.
                        @ 21, 0 CLEAR
                        *--- Put in a new box that matches up with the
status line.
                        @ 21, 8 TO 23,66 DOUBLE
                        @ 13, 5 GET comments OPEN WINDOW Wndow1
                        PLAY MACRO A
                        READ   && Second READ
                        *--- Clear the "CTRL-END" message.
                        @ 12,20 CLEAR TO 12,45

                CASE lkey = uparrow
                        *--- Test for up arrow key
                        LOOP
        
                CASE lkey = pgup
                        *--- Test for page up
                        SKIP -1
        
                        IF BOF()     && If at the first record go to
bottom
                                GO BOTTOM
                        ENDIF
                
                CASE lkey = esc
                        *--- Test for escape key
                        SET CONFIRM OFF
                        @ 22, 4 CLEAR TO 22,71
                        @ 22,27 SAY 'Do you wish to quit?' GET
quitedit PICTURE 'Y'
                        READ
                        SET CONFIRM ON
                
                OTHERWISE   
                        *--- Any other key skips to next record
                        SKIP +1
                        IF EOF()             && If at the last record
go to top
                                GO TOP
                        ENDIF
        
        ENDCASE
        
ENDDO
        
*--- Reset environment and close data files
CLEAR ALL
SET SCOREBOARD ON
SET CONFIRM OFF
SET STATUS ON
SET TALK ON
RETURN
* EOP: QMemo
                                                                                                                   