DEFINE rec RECORD v_type VARCHAR(30), v_color VARCHAR(30) END RECORD MAIN OPTIONS INPUT WRAP OPEN FORM f1 FROM "form1" DISPLAY FORM f1 INITIALIZE rec.* TO NULL CALL input()END MAIN FUNCTION input() INPUT BY NAME rec.* ATTRIBUTES(UNBUFFERED, WITHOUT DEFAULTS) AFTER FIELD v_type IF NOT check_values(DIALOG) THEN CONTINUE INPUT END IF ON ACTION search IF NOT check_values(DIALOG) THEN CONTINUE INPUT END IF MESSAGE SFMT("Search with %1 and %2",rec.v_type,rec.v_color) END INPUTEND FUNCTION FUNCTION check_values(d ui.Dialog) IF rec.v_type NOT MATCHES "[CB]*" THEN ERROR "Type must start with C or B" CALL d.nextField("v_type") RETURN FALSE END IF IF rec.v_color IS NULL THEN ERROR "Must enter color to search" CALL d.nextField("v_color") RETURN FALSE END IF RETURN TRUEEND FUNCTION
LAYOUTGRID{Type: [f1 ]Color: [f2 ] [b1 ]}ENDENDATTRIBUTESEDIT f1 = FORMONLY.v_type;EDIT f2 = FORMONLY.v_color;BUTTON b1 : search, TEXT="Search";END
TYPE vehicle_def RECORD v_type CHAR(1), v_license STRING, v_color STRING END RECORD DEFINE all_types DYNAMIC ARRAY OF STRINGDEFINE veh_rec vehicle_def MAIN DEFINE v_type STRING OPTIONS INPUT WRAP LET all_types[1] = "BOAT" LET all_types[2] = "CAR" LET all_types[3] = "MOTORCYCLE" LET all_types[4] = "TRUCK" OPEN FORM f1 FROM "demo" DISPLAY FORM f1 INPUT BY NAME v_type, veh_rec.v_license, veh_rec.v_color WITHOUT DEFAULTS ATTRIBUTES(UNBUFFERED) ON CHANGE v_type CALL set_completer(DIALOG, v_type) AFTER FIELD v_type IF valid_vehicle_type(v_type) THEN LET veh_rec.v_type = parse_vehicle_type(v_type) ELSE NEXT FIELD v_type END IF ON ACTION search IF LENGTH(veh_rec.v_license) = 0 THEN ERROR "license required" NEXT FIELD v_license END IF CALL search_vehicle() ON ACTION accept ACCEPT INPUT AFTER INPUT IF NOT validate_vehicle(DIALOG) THEN CONTINUE INPUT END IF CALL add_vehicle() END INPUT END MAIN FUNCTION set_completer(d, p) DEFINE d ui.Dialog, p STRING, items DYNAMIC ARRAY OF STRING, i INT IF p.getLength() > 0 THEN LET p = p, "*" FOR i = 1 TO all_types.getLength() IF all_types[i] MATCHES p THEN LET items[items.getLength()+1] = all_types[i] END IF END FOR END IF CALL d.setCompleterItems(items)END FUNCTION FUNCTION parse_vehicle_type(v_type STRING) IF LENGTH(v_type) > 0 THEN RETURN v_type.getCharAt(1) ELSE RETURN NULL END IFEND FUNCTION FUNCTION valid_vehicle_type(v_type STRING) DEFINE t CHAR(1) IF LENGTH(v_type) > 0 THEN LET t = v_type.getCharAt(1) IF t MATCHES "[BCMT]" THEN RETURN TRUE ELSE ERROR "invalid vehicle type" RETURN FALSE END IF ELSE RETURN FALSE END IFEND FUNCTION FUNCTION validate_vehicle(d ui.Dialog) IF LENGTH(veh_rec.v_type) = 0 THEN ERROR "vehicle type required" CALL d.nextField("v_type") RETURN FALSE END IF IF LENGTH(veh_rec.v_license) = 0 THEN ERROR "license required" CALL d.nextField("v_license") RETURN FALSE END IF RETURN TRUEEND FUNCTION FUNCTION add_vehicle() DISPLAY SFMT("add_vehicle(): %1-%2-%3", veh_rec.v_type, veh_rec.v_license, veh_rec.v_color)END FUNCTION FUNCTION search_vehicle() DISPLAY SFMT("search_vehicle(): %1-%2-%3", veh_rec.v_type, veh_rec.v_license, veh_rec.v_color)END FUNCTION
LAYOUTGRID{Type: [f1 ]License: [f2 ][b1 ]Color: [f3 ] [b2 ]}ENDEND ATTRIBUTESEDIT f1 = FORMONLY.v_type,UPSHIFT,COMPLETER;EDIT f2 = FORMONLY.v_license,UPSHIFT;EDIT f3 = FORMONLY.v_color,UPSHIFT;BUTTON b1 : search, TEXT="Search";BUTTON b2 : accept, TEXT="Add/Update";END
ON ACTION search INFIELD v_license
BUTTON b1 : search, TEXT="Search";
BUTTON b1 : v_license.search, TEXT="Search";
ON ACTION search LET button_action = "search" ACCEPT INPUT AFTER INPUT IF button_action = "search" THEN LET button_action = NULL { move original ON ACTION search block of code here } CONTINUE INPUT END IF { the usual AFTER INPUT codes }
INPUT ... ATTRIBUTES(UNBUFFERED) AFTER FIELD field1 CALL valid_field1() RETURNING ok, error_text IF NOT ok THEN ERROR error_text NEXT FIELD field1 END IF AFTER FIELD field2 CALL valid_field2() RETURNING ok, error_text IF NOT ok THEN ERROR error_text NEXT FIELD field2 END IF ON ACTION action-name -- Ensure that field1 and field2 are valid before calling the action CALL valid_field1() RETURNING ok, error_text IF NOT ok THEN ERROR error_text NEXT FIELD field1 END IF CALL valid_field2() RETURNING ok, error_text IF NOT ok THEN ERROR error_text NEXT FIELD field2 END IF -- do the action
ON CHANGE approved_by CALL acu_officer_number_autocompleter(DIALOG, go_record.jurisdiction, 3, TODAY, FALSE) AFTER FIELD approved_by CALL acu_officer_number_autocompleter(DIALOG, go_record.jurisdiction, 3, TODAY, TRUE) LET completer.approved_by = acu_strip_code(completer.approved_by) IF valid_mj_code("officer_number",completer.approved_by,go_record.jurisdiction) = FALSE THEN NEXT FIELD approved_by END IF LET go_record.approved_by = completer.approved_by CALL go_load_completer_translations("approved_by")