home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / array.zip / ARRAY.DOC < prev    next >
Text File  |  1993-03-23  |  13KB  |  315 lines

  1.                DATA ENTRY OF ARRAYS IN DESIGNER 
  2.  
  3. March 23, 1993
  4. Author :DANIEL CHILTON
  5.  
  6.         ABSTRACT - Three methods are presented, which allow
  7. applications to exploit the many benefits of using arrays, while
  8. only using the Clarion's normal FORM Procedure to accomplish data
  9. entry.
  10.  
  11.         One of the four examples in the APP requires that the
  12. ARRAY.CLA source code to be edited by deleting exactly 1 character,
  13. but requires no hand coding in Editor. See Fig 1 
  14.  
  15.                ***
  16.  
  17.         DESIGNER does not support array data entry directly. Numbers
  18. and strings may be displayed and edited as ENTRY FIELDs, but not
  19. arrays, or array elements.
  20.  
  21.         Designing a solution to this limitation requires that ENTRY
  22. FIELDS be setup to display the array elements and permit editing. 
  23.  
  24.         The design must create a correspondence between these
  25. variables and the array elements to be entered or edited. These
  26. ENTRY FIELDS must be the same type as the array.
  27.  
  28.         The design must also assure that the values which are
  29. displayed and edited, properly represent the values in the array.
  30.  
  31.         METHOD 1:  ' 1 to 1 with the OVER attribute ' 
  32.                                       99 44/100 % Pure Designer
  33.  
  34.         This is the simplest and fastest executing method. It is
  35. implemented almost entirely in DESIGNER , and requires only a
  36. minuscule source code change.
  37.  
  38.         The first steps of this method create a '1 to correspondence
  39. between each array element, and variables which represent them. EG:
  40.  
  41.         The variable           JAN corresponds to  MONTH[1]
  42.  
  43.                                FEB corresponds to  MONTH[2]
  44.  
  45.                                ...
  46.  
  47.                                DEC corresponds to  MONTH[12]
  48.  
  49. 1.      Use DESIGNER to create the variables, and a file which
  50.         contains them.
  51.  
  52.         They must appear in the same sequence as the corresponding
  53.         array elements. In this case we are using a one dimensional
  54.         array to represent monthly data, so the correct sequence for
  55.         this example, is the common sense one as above.
  56.  
  57.         In multi-dimension arrays, the sequence of variables must
  58.         match the order in which CLARION assigns array elements in
  59.         memory, and the programmers intentions.
  60.  
  61.         For example a two dimensional array representing months in
  62.         financial quarters might be set up as a 4 by 3 array. CLARION
  63.         assigns the elements to memory in the 'natural order.' ie
  64.         MONTH[1,1]  is first (JANUARY) , MONTH[1,2] is second
  65.         (FEBRUARY) ... MONTH [4,3] is last (DECEMBER.) 
  66.  
  67. 2.      Create a group structure that contains the variables.
  68.  
  69. 3.      Create another group in the same file that contains the array.
  70.         It must match the first group's data type and number of
  71.         elements. (Twelve longs, for example.)
  72.  
  73.         In Designer use: ",OVER(GROUP1) ! Delete 1st ! " as the
  74. DESCRIPTION of this group.
  75.  
  76.         This description appears beside the array declaration in the
  77. source code preceded by an exclamation point, and is therefore
  78. treated as a comment. Delete the first '!' in this line , and the
  79. 'comment' will be treated as code. The code in this example invokes
  80. the OVER attribute. The OVER attribute tells the CLARION COMPILER
  81. to use the same memory for the variables as the array. In this way
  82. the variable names and the corresponding array elements become
  83. identical. The programmer is free to use the variable name or array
  84. element name, for the same datum.
  85.  
  86.  
  87. 4.      Design a table and form. Let DESIGNER populate the form with
  88. the variables.
  89.  
  90. 5.      Through-out the application, use the array or variables as you
  91.         like. They  will be IDENTICAL.
  92.  
  93. 6.      After the .APP is created, but before compiling, invoke the
  94.         OVER attribute in the source code containing the GROUP data
  95.         structures. The over attribute should specify that the second
  96.         group is OVER the first.
  97.  
  98. Fig 1 Edit ARRAY.CLA
  99.  
  100.         Before:
  101. GROUPA2                 GROUP         ! ,OVER(GROUPA1) !delete 1st !
  102.  
  103.         After:
  104. GROUPA2                 GROUP          ,OVER(GROUPA1)  !DELETED 1ST ! 
  105.  
  106.  
  107.         This trick - Deleting the '!' - reduces the coding in EDITOR,
  108. and helps the programmer use DESIGNER almost entirely. Using it,
  109. the programmer can continue to use DESIGNER to change applications
  110. without requiring significant programming in EDITOR with each
  111. change in the application. 
  112.  
  113.         Some programmers may wish to totally eliminate unnecessary use
  114. of EDITOR while developing their application. Doing so may avoid
  115. continually editing new code generated by DESIGNER as changes are
  116. made there. Finally when the application is finished, a slower
  117. executing 'ALL DESIGNER' method can be replaced by this faster ' 1
  118. to 1 OVER ' method by a simple code change.
  119.  
  120.         METHOD 2: 1 to 1 GROUP EQUATE METHOD - 100% Pure Designer
  121.  
  122.         As in the 1-1 OVER method groups are created to contain the
  123. array and the variables to which they correspond.
  124.  
  125.         The Group Equate Method requires that data be moved to and
  126. from the array and the corresponding variables. As the name
  127. suggests a Group assignment statement makes the groups EQUAL in
  128. value .
  129.  
  130.         Instead of making them IDENTICAL at compile time using the
  131. OVER attribute, this method makes them EQUAL during execution of
  132. the program.
  133.  
  134.         The Group assignment statement is syntactically identical to
  135. variable assignment statements. EG 
  136.  
  137.         MEM:GROUPA = FIL:GROUPB
  138.  
  139.         They should be placed in the setup procedure of forms, to make
  140. the variables equal to the array, and in computed fields to make
  141. the array equal to the variables. In this way the variables ( on
  142. the screen ) will always be equal to the corresponding array
  143. elements ( in the record ) .
  144.  
  145.         The steps for this method are:
  146.  
  147. 1.      Define variables in MEMory, and contain them in a group, just
  148.         as in the previous method. 
  149.  
  150. 2.      Define the corresponding array and contain it in a group. It
  151.         should be defined in your file. As before , the array should
  152.         match the number and type of variables in the previous group.
  153.  
  154.  
  155. 3.      In every form using the array you must:
  156.  
  157.         1.     Set the MEMory group to the array group in the SETUP
  158.         PROCEDURE. This assures that the FORM will contain the proper
  159.         values from the start.
  160.         EG: MEM:GROUP = FIL:GROUP
  161.  
  162.         2.     Populate the form with variables from MEMory and the
  163.         file.
  164.                If the array is Very Large, you may want to let DESIGNER
  165.         to populate the form with these MEMory variables. Do so by
  166.         selecting MEMory as the File name when you create the Form.
  167.         Then populate the form with the MEMory variables. Then select
  168.         the correct File name, and edit the form, as necessary.
  169.  
  170.         3.     Create a computed field which sets the Array Group to the
  171.         MEMory Group. This assures that the file's array always
  172.         contains the new data as it gets typed in.
  173.  
  174.         EG:
  175.  
  176.                Computed Field               
  177.   Name        :SCR:SC1                      
  178.   Picture     :@S1                          
  179.   Expression  :' ';F2:GROUPB1=MEM:GROUP0    
  180.  
  181.  
  182.                This is my favorite way to get code into DESIGNER. The
  183.         @S1 picture token assures that the field is represented by a
  184.         visible '■' in Designer.
  185.  
  186.                This computed field is executed repeatedly as the
  187.         variables change on the screen and in MEMory. It maintains the
  188.         proper value of the array elements as these changes occur.
  189.  
  190.         Some applications using a '1 to 1' method may be difficult to
  191. operate. Arrays with multiple dimensions or many elements will be
  192. more difficult to work with. They may require many clicks to get
  193. the cursor to some fields. So we need to consider more user
  194. friendly methods. After all, we write programs for users. Right ?
  195.  
  196.         METHOD 3: '1 to Many'  using  Computed Assignment.
  197.  
  198.         The previous examples used a 1 to 1 correspondence between the
  199. fields that appeared on the form , and the array elements.
  200.  
  201.         A '1 to many' correspondence can be set up to simplify data
  202. entry, however it complicates the programming task.
  203.  
  204.         In this method the values of the array are displayed one-at-a-
  205. time in a 'Value Field.' An 'Index Variable ', containing an index
  206. to the array, determines which array element gets displayed and
  207. edited in the 'Value Field.'
  208.  
  209.         More than one dimension can be handled by this method, but a
  210. one dimensional array serves as a good example. Two or more indices
  211. may be needed to handle the higher dimensions.
  212.  
  213.         Two ( or more ) MEMory fields can be set up to accomplish the
  214. data entry for this method. Computations performed in the
  215. edit_procedures of these MEMory fields move data to and from the
  216. array, into and from  the 'Value field.'
  217.  
  218.         The steps for this method are:
  219.  
  220. 1.      Define one integer variable for the 'Index Variable' in
  221.         MEMory, and another variable for the 'Value Field.' The 'Value
  222.         field' must be the same data type as the array elements. You
  223.         should set upper and lower limits on the Index, which can be
  224.         a 'SHORT ' data type.
  225.  
  226. 2.      Create a file that contains the array. It need not contain a
  227.         GROUP structure. 
  228.         
  229. 3.      For each form in which you want to edit the array, you must do
  230.         the following:
  231.  
  232.         1: Initialize the Value field. Do this in the SETUP PROCEDURE
  233.         of the form. You may also need to initialize the Index
  234.         Variable.
  235.         For example:
  236.  
  237.         MEM:NDX=1 ; MEM:VALUE=F2:ARRAY[1]
  238.  
  239.         The choice for the default for the Index Variable depends on
  240.         your application. You may wish to allow the operator set it in
  241.         an entry field in the table, just before using the form.
  242.  
  243.  
  244.         2: Place an 'Index Field' in the form. This is optional. This
  245.         method works as long as THERE IS an index value. 
  246.         In the EDIT PROCEDURE of this field, assign the array element
  247.         specified by the new value of the Index field to the Value
  248.         field. Use the DISPLAY statement to display this value.
  249.         
  250.         EG: MEM:VALUE = F2:ARRAY[MEM:NDX] ; DISPLAY
  251.  
  252.         3: Place the 'Value Field' in the form. In the EDIT PROCEDURE
  253.         of the 'Value Field' , assign the 'Value Field' to the array
  254.         element. The value of the Index field is used as the index to
  255.         the array.
  256.         
  257.         EG:  F2:ARRAY[MEM:NDX] = MEM:VALUE  ; DISPLAY 
  258.  
  259.         Variations on a theme:
  260.  
  261.         These three steps will work , but may be difficult for the
  262.         operator to use. I recommend the addition of any of the
  263.         following steps to enhance the ease of use and functionality
  264.         of the application.
  265.  
  266.         4A:    In the edit procedure of the Value field, where n= limit
  267.                of the index, increment the Index as follows:
  268.                        Index = ( Index MOD N ) + 1
  269.                        Set the Value field to this array element.
  270.                        Use the DISPLAY statement to display these new
  271.                        values.
  272.  
  273.         4B     Use SELECT() in the EDIT PROCEDURE of the Index field to
  274.                move the cursor back to the Value field for more data
  275.                entry. This helpful for repeated data entry. The
  276.                keycode() is tested for keycode() = 257. (257 = ENTER)
  277.                CTRL-ENTER ends data entry.
  278.  
  279.         4C     Use Alerted keys to increment the index. Page UP and Page
  280.                Down are good choices. The cursor can stay in the Value
  281.                field using SELECT(). In this case the Index field can be
  282.                'Display Only' rather then 'Edit Field.'
  283.  
  284.         4D     Use COMPUTED FIELDS  OR  DISPLAY FIELDS to display other
  285.                elements of the array.
  286.  
  287.         4E     Use a pointer to indicate which element is being edited.
  288.                Display each array element. Along side each element put
  289.                a CONDITIONAL FIELD which displays "==>" or "   "
  290.                depending on the value of your index.
  291.  
  292.  
  293.         Entry Field                                 
  294.                                                                   
  295.            
  296. Field Name    :MEM:VALUE          File Access Key :       
  297. Edit Procedure:  
  298.         F2:ARRAY[MEM:NDX]=MEM:VALUE;                  !* update array value
  299.         IF KEYCODE()=257 THEN;                        !* test for ENTER KEY
  300.         MEM:NDX=MEM:NDX % 12 +1;                      !* increment Index mod 12
  301.         MEM:VALUE=F2:ARRAY[MEM:NDX];                  !* set variable to array value
  302.         SELECT(3);END                                 !* move cursor to EDIT FIELD
  303.  
  304.      This EDITED Clarion Screen Shows the implementation of some of
  305. these suggestions.
  306.  
  307.  
  308.      The  subroutine used in the report example totals values in
  309. the Array from START to FINISH 'wrapping around' if necessary.  EG:
  310.  
  311.  
  312. From November - 11th month  
  313.      to March - 3rd month.
  314.      ( 11+12+1+2+3 )
  315.