Using a Data Form with a Choice List

To use a form with one or more choice lists requires a few additional steps. If you are using the Designer's Main Generator to generate your main program, these steps are included automatically.

First, when including the header files, you must include vv_clist.h to enable the Vermont Views choice list facility.

Second, before getting the form from the library, you must define a memory file with mf_def(). At this time, you do not have to read in the text file. You just need a pointer to the memory file that will contain the choice lists for the fields on the form so that you can pass this pointer to dl_fmget().

In the next example, we add a choice list to the job type field on des_form. The code for this is shown below, and is available in the tutorial des_clist.c.

Note that you must read in the text to the choice list memory file using the function mf_rd() before you process the form. If you use the Designer's Main Generator to generate your main program, it will include the code necessary to read a file called clist.txt from the disk. The Main Generator will also create a sample clist.txt file that contains all necessary keywords and sample choices. You will need to modify this file to add the correct choices for your application. You should refer to Chapter 12, "Choice Lists" for instructions on how to write or modify a keyworded text file for choice lists and how to read the text file into a memory file.

#include <vv_str.h>            /* String fields on des_clist        */

#include <vv_date.h>            /* Date fields on des_clist        */

#include <vv_int.h>            /* Integer fields on des_clist    */

#include <vv_dec.h>            /* Decimal fields on des_clist    */

#include <vv_help.h>            /* Enable the help system        */

#include <vv_clist.h>            /* Enable choice list system        */

#include <vv_des.h>            /* Use Designer form            */

#include <vv_main.h>            /* Global system declarations        */

#include <prototyp.h>            /* Function prototypes for form    */

#include <des_tut.h>            /* Function list for all functions    */

#include <des_form.h>            /* Data structure for des_clist    */    



#ifdef LINT_ARGS

int CDECL main(void);

#else

int CDECL main();

#endif



int CDECL main()

{

    DES_FORM des_data;            /* Local storage for des_clist data    */

    DFORMPTR dfmp;                /* VV form pointer for read in form    */

    DLIBPTR libp;                /* VV Designer library pointer    */

    MFILEPTR mf_clistp;            /* VV memory file for choice list    */



    vv_init();                /* Initialize Vermont Views        */

    vs_clr();                /* Clear the screen            */



    /* Define a memory file and read in choice list                */

    mf_clistp = mf_def(20, 50);

    mf_rd("clist.txt", mf_clistp);



    /* Open the Designer library "des_tut.vvd"                    */

    libp = dl_open("des_tut.vvd");



    /* Read out "des_clist" store data in des_data, use function list    */

    /* des_tut, use choice list memory file mf_clistp                */

    dfmp = dl_fmget("des_clist", &des_data, des_tut, mf_clistp, libp);



    dl_close(libp);            /* Close the Designer library        */

    fm_proc(0, dfmp);            /* Process the form            */

    fm_free(dfmp);                /* Free the form                */

    mf_free(mf_clistp);            /* Free the memory file            */

    vv_exit();                /* Exit Vermont Views            */

    return(0);

}


Home Contents Previous Next