Hands On
Modifying Values in ArcPad
Continued from page 53
AplFile.Open INIPath & "\" + strINI + _ ".ini",2 Set pTheComboBox = Application. _ Applets("Demo.apa") _ .Forms(strForm)_ .Pages(strPage) _ .Controls(strControl) ‘Write the header of the INI file AplFile.WriteLine("[" + strHeader + "]") For a = 0 To pTheComboBox .ListCount - 1 ‘Move to each item in ComboBox pTheComboBox .ListIndex = a AplFile.WriteLine(pTheComboBox .Value) Next pTheComboBox .ListIndex = 0 ‘Close INI file AplFile.Close ‘Clear variables Set AplFile = Nothing Set pTheComboBox = Nothing Set a = Nothing Conclusion In summary, there are two parts to this strategy. The first part creates a preference dialog that allows editing of the INI files that the combo boxes use for values inside the applet. This allows a simple option to add choices to the combo boxes in the field, when needed, by just pressing a button on the toolbar. Plus, it still allows users to edit the INI text file outside of ArcPad. The second part is adding the LoadCombos subroutine. This is the subroutine called by all combo boxes, either on the preference form or any form, which has a ComboBox with values stored in an INI file. If you didn't want to create the preference form, you could just add the LoadCombos sub and the OnSetFocus event. The combo boxes will still read the INI files for their values, and the user can still edit the INI file outside of ArcPad with a simple text editor. The disadvantage of reading INI files for combo boxes is that it takes far more programming to get a list of values for a combo box. But, it does add the most flexibility for adding new values. This is just another choice to pick from when using a ComboBox and is not perfect to use in every instance. Sometimes, just filling in the list values is the best choice when you know all the items and you know the list won't change. This is why a well-planned application is always a good first step to any new project. For more information, contact Craig Gallant Senior Designer LJB Inc. E-mail: cgallant@ljbinc.com
End Sub Listing 9: Add the WritePrefs subroutine. One last piece of code needs to be added to the applet for the preference dialog to work. If there is already a toolbar in the applet, all that needs to be done is add a button to the toolbar. If not, add a toolbar to the applet first, then add the preference button to the toolbar. On the OnClick event of the button, add the code Applet.Forms("thePreferenceFormName").Show This code will display the preference dialog when the button is pressed on the toolbar.
ArcUser Fall 2009
www.esri.com