Exercise 2: Creating custom forms and writing scripts for shapefiles
Creating a custom data entry form with data validation for a layer
Next, you will create a layer definition file by using the new layer definition file Form Wizard dialog box. Layer definition files provide a way to deliver customizations that are loaded with data.
This exercise introduces the basic techniques for creating custom forms and writing scripts to perform initialization and data validation for shapefiles. You will use the Trees shapefile, which is located in the Tutorial folder below the \\Program Files\ArcGIS\ArcPad\Developer\Samples\ folder.
Creating a layer definition file
- Start ArcPad Studio. Click the New Layer Definition button on the toolbar.
- Navigate to the Tutorial folder and click the Trees.shp file located at \\Program Files\ArcGIS\ArcPad\Developer\Samples\Tutorial.
- Click the Open button. The Form Wizard dialog box appears to assist in quickly generating data entry forms. On the Layout tab, you can modify the form's properties such as the form size, the pages visible on the form, and the text and background properties. Select all the page check boxes so they will be visible. First, select the fields you want to display on the form. See the following screen shot:
- Click the Fields tab. Select the ID, OWNER, COM_SPECIES, DBH, HEIGHT, and IDP check boxes to display on the form for the user to view. See the following screen shot:
- Click the Controls tab to add the required controls and additional parameters to the controls on the form, since you require values to be entered properly when the feature attributes are being collected.
- Select the OWNER, COM_SPECIES, DBH, HEIGHT, and IDP check boxes.
- You also require a numeric value for the Diameter at Breast Height (DBH) and HEIGHT attributes. The DBH for a tree's diameter measurement must have a defined minimum and maximum range. The city trees' range is between 6 to 36 inches (you will limit the selection to that range). Type 6 in the DBH Minimum field and 36 in the DBH Maximum field.
- The city trees' height range is around 15 to 100 feet. Type 15 in the HEIGHT Minimum field and 100 in the HEIGHT Maximum field.
- You will also change how a label is defined to make the presentation of field information more informative to the user. Click the ID field's label text box on the Form Wizard dialog box. Change the Label text value from Id to ID. Change Com_SPECIES to Species, and IDP to Problem. See the following screen shot:
- Click OK on the Form Wizard dialog box to keep your changes. The result of your choices on the Form Wizard dialog box is shown in a tree view as a new layer definition file created with the <ArcPad> root element and the <LAYER> child element. See the following screen shot:
- Double-click <LAYER> in the tree view to set the layer definition file's properties.
- Type City Trees in the Name text box and click OK. The name attribute is added to the <LAYER> element in the tree view. See the following screen shot:
- Click the Save button on the toolbar to save the layer definition file (save your file periodically when editing in case something unexpected occurs).
For the purpose of demonstrating how to make edits to the layer definition file, you will link the OWNER, COM_SPECIES, and IDP controls to an external database table for list values in a later step.
In this example, you could have manually added list values to be used as parameters of the available OWNER choices. For example, you could list potential owners such as Diane, Craig, and Ben as possible selection values. These selection values can be added directly as parameters on the Form Wizard dialog box.
Modifying an Edit form generated from the Form Wizard dialog box
When a form has been created through the Form Wizard dialog box, changes can be made to the attributes and properties for that form.
- Click the <EDITFORM> Trees element. The Trees Edit form appears.
- Click the Form menu and click Form Properties. See the following screen shot:
- The Form Properties dialog box appears after you select Form Properties on the preceding screen shot. This dialog box resembles the previous Form Wizard dialog box and you can make changes to the form's properties here. For example, previously you did not intend to make all of the pages visible on the Form Wizard dialog box. Therefore, to make the changes to display the pages you need, clear the Symbology Page and Attributes Page check boxes.
- Type City Trees in the Caption text box. See the following screen shot:
- Click OK. The form's title bar changes from Trees to City Trees.
Modifying the form's pages
- On the form, click the Page menu and click Page Properties. The Page Properties dialog box appears. You will use this dialog box to gather information about the tree.
- Type Tree Information in the Caption text box. See the following screen shot:
- Click OK to close the Page Properties dialog box. The form looks like the following screen shot:
- The form has unused space at the bottom. You can modify the controls as you want; however, in this tutorial, resize the form by typing 80 in the Height text box (to change the height from 130 to 80).
- On the form, click the Form menu and click Form Properties. The Form Properties dialog box appears. See the following screen shot:
- Click OK to close the Form Properties dialog box. The form now looks like the following screen shot:
- Click OK to close the form.
- Click the Save button on the toolbar to save your layer definition (Trees.apl) file.
Modifying an Edit form further from the Form Wizard dialog box
There may be times when you want to modify the form to a greater extent. You may want the value for a numerically bound control. For example, with the Tree ID, you may want to auto increment the record values as features are added to the map.
- You will make a change to the Tree ID so the records automatically increment as records are added. Select the Tree ID edit control on the form. See the following screen shot:
- Double-click the Tree ID edit control or click the Control menu, then click Control Properties to open the Control Properties dialog box. See the following screen sot:
- Click the Values tab and select the Auto Increment (Numeric bound fields only) check box. Leave the Increment Step text box set to 1 to allow records to increment sequentially (that is, 1, 2, 3, 4, and 5).In this tutorial, you want to use ComboBox controls instead of edit controls to provide a list of choices when there is a minimum amount of space available on the form. You will make changes to the OWNER, COM_SPECIES, and IDP controls to show a list of choices to the user in the drop-down list.
- You will now replace the three edit controls with ComboBox controls added earlier on the Form Wizard dialog box. Select the Owner field on the form (anchors shown). See the following screen shot:
- Click theControl menu, then click Delete Control to remove the control. Once the Owner control field is deleted, do the same for the COM_SPECIE and IDP controls by selecting the Species and Problem control fields. With the controls deleted, the form looks like the following screen shot:
- You will now add new ComboBox controls to replace the deleted controls by clicking the Controls palette, then dragging a COMBOBOX control to where the previous Owner, Species, and Problem control fields were located on the form. See the following screen shot:
- The Control Properties dialog box for the COMBOBOX control becomes visible after you drop the control on the page. Type cboOwner in the Name text box. Click the Field drop-down list and choose OWNER from the list. This links the Owner field to this combo box. You can manually resize and change the placement of a control on the form editor or on the Control Properties dialog box. Next, you will change the width and height properties.
- Type 84 in the Width field and 12 in the Height field to reflect the same size as the predefined control from the Form Wizard dialog box. You will manually align the X and Y placement options with the existing controls later. Leave the Control Properties dialog box open. See the following screen shot:
Once you decide on the control location on the page, you can make changes to the control's attributes and properties to reflect what gets displayed in the combo box. For example, linking ownership information to a stand-alone data table that only contains owner information making it more efficient to update the stand-alone table when needed.
- With the Control Properties dialog box still open, click the Values tab, then click the table icon to browse for a .dbf file. You will use the Tree Ownership.dbf file located with the Tutorial data at \\Program Files\ArcGIS\ArcPad\Developer\Samples\Tutorial.
- Click the Values Field and the Text Field drop-down lists, and select OWNER from the Tree Ownership.dbf file.
- Select the Limit to list check box to ensure that users cannot add values to the table. Limit to list specifies if the text box portion of the combo box can accept text or not. See the following screen shot:
- Click OK to maintain the External List Value choices for the cboOwner control.
- You are now back in the editor form. Move the added control to align with the other controls on the form. See the following screen shot:
- With the Tree Information page still open, add another ComboBox control by clicking the Controls palette (as you did with the cboOwner combo box), then dragging a COMBOBOX control to the location of the previous COM_SPECIE edit control.
- Type cboSpecies in the Name text box. Click the Field drop-down list and choose COM_SPECIE.
- Type 84 in the Width text box and 12 in the Height text box to reflect the same size as the predefined controls from the Form Wizard dialog box. You will manually align the X and Y placement options with the existing controls later. Leave the Control Properties dialog box open. See the following screen shot:
With the Control Properties dialog box still open, you will link the cboSpecies control with the Tree Names.dbf file.
- Click the List Values tab, then the table icon to browse for a .dbf file. You will use the Tree Names.dbf file located with the Tutorial data at \\Program Files\ArcGIS\ArcPad\Developer\Samples\Tutorial.
- Click the Values Field and Text Field drop-down lists, and select COMMON_NAME from the Tree Names.dbf file.
- Select the Limit to list check box to ensure that users cannot add values to the table. Limit to list specifies if the text box portion of the combo box can accept text or not. See the following screen shot:
- Click OK to maintain the External List Values choices for the cboSpecies control.
- You are now back in the editor form. Move the added control to align with the other controls on the form. See the following screen shot:
- You will now add the final combo box control. Click the Control palette (as you did with the cboOwner and cboSpecies combo boxes) and drag a COMBOBOX control to the location of the previous IDP edit control. Type cboProblem in the Name text box. Click the Field drop-down list and select IDP.
- Type 84 in the Width field and 12 in the Height field to reflect the same size as the predefined controls from the Form Wizard dialog box. You will manually align the X and Y placement options with the existing controls later. Leave the Control Properties dialog box open. See the following screen shot:
With the Control Properties dialog box still open, you will link the cboSpecies control with the IDP List.dbf file.
- Click the List Values tab and the table icon on the Control Properties dialog box to browse for a .dbf file. You will use the IDP List.dbf file located in the Tutorial data at \\Program Files\ArcGIS\ArcPad\Developer\Samples\Tutorial. Select the IDP_LIST.dbf file.
- Click the Values Field and Text Field drop-down lists, and select IDP_LIST from the IDP List.dbf file.
- Select the Limit to list check box to ensure that users cannot add values to the table. Limit to list specifies if the text box portion of the combo box can accept text or not. See the following screen shot:
- Click OK to maintain the External List Values choices for the cboProblem control, then click OK again to save changes to the City Trees Tree Information editor form.
- On the City Trees form, you can move the added cboProblem control (or any control) to align with the other controls on the form. You can select any control and move it when the control's anchors are visible. See the following screen shot:
- Click OK to close the City Trees form.
In the final steps, you want to add a SYMBOLOGY element that contains a VALUMAPRENDER and SIMPLELABELRENDERER child element. These come from a layer definition file (.apl) that was pre-defined in another project. You want to use that same defined symbology for your Trees layer, as well as how the features are labeled on the map.
- Click the Open Tool button to open the Trees_OLD_Study.apl file located in the Tutorial folder, then navigate to the folder at \\Program Files\ArcGIS\ArcPad\Developer\Samples\Tutorial. With the Trees.apl and Trees_OLD_Study.apl files open, click the Window menu, then click Tile to view both files simultaneously. Click to expand the Trees_OLD_Study.apl <SYMBOLOGY> elements to see how it is defined. See the following screen shot:In the next step, you will copy the <SYMBOLOGY> element from the Trees_OLD_Study.apl file to the Trees.apl file.
- Select the Trees_OLD_Study.apl window's title bar and copy the <SYMBOLOGY> element from the Trees_OLD_Study.apl file by right-clicking the <SYMBOLOGY> element, then selecting Copy. See the following screen shot:
- Click the window's title bar to activate Trees.apl, right-click the <LAYER> element, then select Paste. The <SYMBOLOGY> element from the Trees_OLD_Study.apl file is now copied to the Trees.apl file.
- Close the Trees_OLD_Study.apl file.
- Click to expand the <SYMBOLOGY> element in the Trees.apl file. See the following screen shot:Note:
The EXACT tag continues on in the list. It is cut off in the screen shot.
- Click the Save button on the toolbar to save the Trees layer definition file (Trees.apl). You are now ready to test and deliver your application to field personnel.