Specifing a Range of Values

You can make sure that the user enters a value within a specified range by assigning a minimum and maximum value allowed for user input. You can do this for fields of all types except Boolean fields, radio buttons, check boxes, and pushbuttons. When you set a range for a field, the information is stored in the data field structure.

Designer: You can specify the range values inside the Designer. See the Designer User's Guide for details. You can also specify the range values in code, at any point after you have read the form from the Designer library.

Code: You can specify the range of a field at any point after defining the field with a fld_def() call.

General: To specify the range of a field in code, use the set field range function, sf_range():

int sf_range(minp, maxp, dfldp)

PTR minp;            /* Pointer to variable holding minimum        */                                /* allowed value                    */

PTR maxp;            /* Pointer to variable holding maximum        */

DFIELDPTR dfldp;        /* Pointer to field to set range for        */

Code: For example, the following code defines two fields to collect the date and grade. The date must be a valid date during the current school year, and cannot be greater than today's date. The grades can range from 0 to 100.

DFORMPTR dfmp;

DFIELDPTR date_fldp, grade_fldp;

UCHAR date[7];

UCHAR *date_earliest, *date_latest;

int grade = 0;

int grade_min = 0;

int grade_max = 100;



date = "  /  /  ";            /* Field data variable             */

                            /* Earliest acceptable date         */

date_earliest = "09/01/91";       



                            /* Latest acceptable date         */

                            /* is today; get today's date     */

date_latest = mem_get(9);

date_get(date_latest, "MM/DD/YY");



dfmp = fm_def(0,0,10,80, LNORMAL, BDR_SLNP);

date_fldp = fld_def(1, 1, "Date: ", FADJACENT, "UU/UU/UU",

            F_DATE, date, dfmp);

sf_range(date_earliest, date_latest, date_fldp);

grade_fldp = fld_def(1, 5, "Grade: ", FADJACENT, "UUU",

            F_INT, (PTR) &grade, dfmp);

sf_range(&grade_min, &grade_max, grade_fldp);

Caution: A string variable is, by definition in C, a pointer, and you should not precede the names of string data variables with an '&'. String variables are used for string fields, date fields, and time fields.

Designer: Ranges can be specified in the Designer. If you want to specify the range in your code, you can get a pointer to the desired field and then call sf_range(). For example, the following code sets ranges on two fields to collect the date and grade. The date must be a valid date during the current school year, and cannot be greater than today's date. The grades can range from 0 to 100.

DLIBPTR libp;

DFORMPTR dfmp;

DFIELDPTR date_fldp, grade_fldp;

UCHAR *date_earliest, *date_latest;

int grade_min = 0;

int grade_max = 100;



date_earliest = "09/01/91";        /* Earliest acceptable date         */



date_latest = mem_get(9);        /* Latest acceptable date         */

date_get(date_latest, "MM/DD/YY");    /* is today; get today's date     */





dlibp = dl_open("my_lib");

dfmp = dl_fmget("grades", NULLP, NULLP, NULLP, dlibp);

date_fldp = i_namptr("date", dfmp);

sf_range(date_earliest, date_latest, date_fldp);

grade_fldp = i_namptr("grade", dfmp);

sf_range(&grade_min, &grade_max, grade_fldp);

Caution: A string variable is, by definition in C, a pointer, and you should not precede the names of string data variables with an '&'. String variables are used for string fields, date fields, and time fields.


Home Contents Previous Next