Steps to Adding a Memo Field to a Form

Designer: See the Designer User's Guide for more information about adding memo fields to your Designer forms.

Code: The tutorial program memo_fld.c, listed below, defines a data form with one memo field on it. The memo buffer is larger than the field it is displayed in.

#include <vv_memo.h>
/* Include memo header file
*/
#include <vv_main.h>
/* Include main header file
*/
#define MEMO_COLQ  78
   
#define MEMO_ROWQ  20



   
int main(void)
   
{
   
    DFORMPTR dfmp;
/* Declare pointer to data form
*/
    MEMOPTR memop;
/* Declare pointer to memo field
*/
    UCHAR *datap;
/* Declare underlying data variable
*/
int size_memo;



   
vv_init();
/* Initialize Vermont Views  
*/
    /* Allocate and initialize memory for data variable to hold memo    

    size_memo = (MEMO_COLQ + 1) * MEMO_ROWQ;

    datap = mem_get(size_memo);
*/
    /* Allocate & initialize form                                dfmp = fm_def(0, 0, 15, 80, LNORMAL, BDR_DLNP);
*/
    /* Define memo field                                      memop = memo_def(0, 0, "Memo:", FBELOW, 12, 78, datap,

            dfmp, MEMO_ROWQ, MEMO_COLQ);
*/
    fm_proc(0, dfmp);
/* Process form
*/
    /* Collect data from the data variable (not shown)
*/
    fm_free(dfmp);
/* Free memory for form
*/
    mem_free(datap);
/* Free memory for memo  
*/
    vv_exit();
/* Exit Vermont Views system  
*/
    return(0);
   
}

The procedures for defining a data form are the same as described in Chapter 6, "Writing Forms in Code." The additional steps needed for including a memo field on the form are listed below:

1 Include the header file vv_memo.h.
2 Allocate and initialize the data variable for the memo field.
3 Define the memo field with memo_def().

A detailed explanation of these steps follows.

Step 1: Include the header file vv_memo.h.

The header file vv_memo.h must be included in all modules that use or reference memo fields. vv_memo.h includes all #defines, global variables and function prototypes needed to use memo fields. As always, vv_main.h must be included in the main module.

Step 2: Allocate and initialize the data variable for the memo field.

The data variable for the memo field should have enough bytes for each character in the memo field, plus a newline character for each row and a terminal null to mark the end of the entire memo field. To determine the size of the data variable, use the following formula:

(memo_colq + 1) * memo_rowq

The number (memo_colq + 1) represents the number of characters in a row plus a character for the space or newline character that is appended to each row. A terminal null is appended to the last row instead of a space or newline character. This is multiplied by the number of rows. The size of the allocated data variable must be less than 65536 bytes.

If you use mem_get() to allocate memory for the data variable, the contents of the variable are already initialized to zeros. If you use another method to allocate the variable and you do not want anything displayed in the memo field when the form is initially displayed, either set the INITIALBLANKS option to ON or make the first character of the memo data variable a null terminator:

*datap = '\0';

Step 3: Define the memo field with memo_def().

To define a memo field, use the memo definition function memo_def():

MEMOPTR memo_def(prompt_rb, prompt_cb, prompt, memo_cb, rowq, colq, datap,

                 dfmp, memo_rowq, memo_colq)
 
int prompt_rb;
/* Row in window to begin prompt (or memo)
*/
int prompt_cb;
/* Column of form window to begin prompt
*/
UCHAR *prompt;
/* Pointer to prompt string
*/
int memo_cb;
/* Column to begin memo field display area
*/
int rowq;
/* Number of rows in memo field display area
*/
int colq;
/* Number of columns in memo field display area
*/
UCHAR *datap;
/* Pointer to data variable to hold memo contents
*/
DFORMPTR dfmp;
/* Pointer to form to put memo on
*/
int memo_rowq;
/* Rows in memo buffer
*/
int memo_colq;
/* Columns in memo buffer 
*/

For prompt_rb and prompt_cb, specify the row and column in which to place the first character of the prompt. If you do not want a prompt, do the following: use prompt_rb and prompt_cb to specify the row and column to begin the memo display area, pass NULLP for prompt, and specify FADJACENT for memo_cb.

For memo_cb, you can specify a column number, or use one of the following values: FADJACENT, to place the memo field immediately after the prompt; FABOVE, to place the memo field immediately above and in the same column as the prompt; or FBELOW, to place the memo field immediately below and in the same column as the prompt.

The size of the memo buffer, as specified by memo_rowq and memo_colq, should be the same as or greater than the size of the memo field display area.

This function sets the active attribute by default to LFLDACT, the inactive attribute to LFLDINACT, and the skip attribute to LFLDSKIP.

Naming Tip: Functions dealing with memo fields contain the entire word "memo".


Home Contents Previous Next