Modifying Values in ArcPad
Continued from page 51
‘Enable the save button pWriteButton.Enabled = True ‘Do not reread INI file Application.UserProperties _ ("strCboUpdate1") = "False" End If If pTheCheckBox.Value = ‘Enable the textbox and the add button pAddButton.Enabled = True pTheTextBox.Enabled = True Else ‘Disable the textbox and the add button pAddButton.Enabled = False pTheTextBox.Text = "" pTheTextBox.Enabled = False End If .Pages("pgPage01") _ .Controls("txtEdit1") Set pAddButton = Application.Applets_ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01") _ .Controls("btnAdd1")
‘Clear variables Set pTheComboBox = Nothing Set pWriteButton = Nothing Set strDeleteValue = Nothing Listing 3: OnClick event of the Delete button OnClick Event for the Update Button The update button writes the INI file from the list in the combo box. (Refer to Listing 4.) In the OnClick event of the update button, add the call to the WritePrefs subroutine in the applet's VBScript to pass it the values for the INI file. Next, set the update button to enabled and its value to false. This is done so the event cannot be called again until something changes. Dim pWriteButton Set pWriteButton = Application.Applets _ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01")_ .Controls("btnWrite1") ‘Call the WritePrefs sub and pass arguments ‘Form name, Page name, Control name, INI file ‘name, Header title Call WritePrefs("frmPref", "pgPage01", _ "cboHydrant", "Hydrant", "Hydrant")
‘Clear variables Set pTheCheckBox = Nothing Set pTheTextBox = Nothing Set pAddButton = Nothing Listing 5: OnClick event for the check box OnClick Event for the Add Button The last thing on this form is the OnClick event for the add button. (Refer to Listing 6.) Add an if statement to verify if the text box has a value. If the text box contains a value, add that value to the list for the ComboBox and clear the value from the text box. Next, enable the Update button and set the global variable to false so the ComboBox will not reread the INI file and erase the value that was just added. Dim pTheComboBox , pTheTextBox, pWriteButton, _ strAddValue Set pTheComboBox = Application.Applets _ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01") _ .Controls("cboHydrant") Set pTheTextBox = Application.Applets _ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01") _ .Controls("txtEdit1") Set pWriteButton = Application.Applets _ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01") _ .Controls("btnWrite1")
‘Disable the save button pWriteButton.Enabled = False
‘Clear variables Set pWriteButton = Nothing Listing 4: OnClick event for the Update button OnClick Event for the Check Box The check box OnClick event enables the text box to be editable. (Refer to Listing 5.) Modify the check box by adding an if statement to verify if the value has been checked. If the value is checked, the enabled value is set to true for the text box and the add button. If the value is false, the enabled value is set to false for the text box and the add button. Dim pTheCheckBox, pTheTextBox, pAddButton Set pTheCheckBox = Application.Applets _ ("Demo.apa").Forms("frmPref")_ .Pages("pgPage01") _ .Controls("chkEdit1") Set pTheTextBox = Application.Applets _ ("Demo.apa").Forms("frmPref")_
52 ArcUser Fall 2009
‘Check to see if textbox has a value If pTheTextBox.Value <> "" Then strAddValue = pTheTextBox.Value ‘Add textbox value to combo box pTheComboBox .AddItem strAddValue, _ strAddValue pTheComboBox .ListIndex = 0
www.esri.com