English

How To: Access and modify ArcPad preferences from a VBScript

Summary

There is no direct access to most of the ArcPad preferences from VBScript. These preferences are stored in ArcPadPrefs.apx and exposed to the user in the ArcPad Options dialog box.

A few preferences can be accessed via the Properties property of the Application object, but most require reading from and/or writing to ArcPadPrefs.apx directly.

Procedure

Since ArcPadPrefs.apx is an XML file, we can use the MSXML DOM to read and write preferences in a VBScript.

Warning:
The MSXML DOM is present on all Windows 9x/NT/2000/XP and Pocket PC devices; however it is not present on CE 2.x and some CE 3.0 devices. If the MSXML DOM is not present on your CE 3.0 device, please contact the device manufacturer and ask for it to be included.


The Customizing ArcPad online help contains all the valid elements, attributes, and values in ArcPadPrefs.apx. These are located in the PREFERENCES element topic.

  • For example, here's a subroutine that turns point averaging on and sets it to the input value in ArcPad 7, 8 and 10:
    Code:
    Sub SetPointAveraging (p_AvgTime)

    'Path to ArcPadPrefs.apx file

    Dim strArcPadAPX

    strArcPadAPX = Application.System.Properties("PersonalFolder") & "\My ArcPad\ArcPadPrefs.apx"



    'Attempt to create a reference to the MSXML DOM

    On Error Resume Next

    Dim pXML

    Set pXML = CreateObject("Microsoft.XMLDOM")

    If Err.Number <> 0 Then

    MsgBox "MSXML is not present on this device.", vbCritical, "No MSXML"

    Exit Sub

    End If

    On Error GoTo 0



    'Read in ArcPadPrefs.apx

    Dim blnExists

    blnExists = pXML.Load(strArcPadAPX)



    Dim pNewElement ' Used for new elements that may need to be created alongthe way



    'If it doesn't exist, create one

    If Not blnExists Then

    Set pNewElement = pXML.createNode(1,"ArcPad","")

    Set pXML.documentElement = pNewElement

    Set pNewElement = pXML.createNode(1,"PREFERENCES","")

    pXML.documentElement.appendChild(pNewElement)

    Set pNewElement = Nothing

    End If



    'Get the GPS and PREFERENCES element

    Dim pPREFSElement, pGPSElement

    Set pPREFSElement = pXML.documentElement.selectSingleNode("PREFERENCES")

    Set pGPSElement = pPREFSElement.selectSingleNode("GPS")



    'If the GPS element doesn't exist, create it

    If pGPSElement Is Nothing Then

    Set pNewElement = pXML.createNode(1,"GPS","")

    Set pGPSElement = pPREFSElement.appendChild(pNewElement)

    Set pNewElement = Nothing

    End If



    'Get the AVERAGING element

    Dim pAVGElement

    Set pAVGElement = pGPSElement.selectSingleNode("AVERAGING")



    'If it doesn't exist, create it

    If pAVGElement Is Nothing Then

    Set pNewElement = pXML.createNode(1,"AVERAGING","")

    Set pAVGElement = pGPSElement.appendChild(pNewElement)

    Set pNewElement = Nothing

    End If



    'Set the attributes of the AVERAGING element

    pAVGElement.setAttribute "enabled", "true"

    pAVGElement.setAttribute "point", p_AvgTime



    'Save the changes to ArcPadPrefs.apx

    pXML.Save strArcPadAPX



    'Free resources

    Set pXML = Nothing

    Set pPREFSElement = Nothing

    Set pGPSElement = Nothing

    Set pAVGElement = Nothing



    'Force ArcPad to reload the settings from ArcPadPrefs.apx

    Dim blnSuccess

    blnSuccess = Preferences.Read
    End Sub


    • Here's the equivalent subroutine for use with ArcPad 6.0.x:

    Code:
    Sub SetPointAveraging (p_AvgTime)
    'Path to ArcPadPrefs.apx file
    Dim strArcPadAPX
    strArcPadAPX = Application.System.Properties("PersonalFolder") & "\ArcPadPrefs.apx"

    'Attempt to create a reference to the MSXML DOM
    On Error Resume Next
    Dim pXML
    Set pXML = CreateObject("Microsoft.XMLDOM")
    If Err.Number <> 0 Then
    MsgBox "MSXML is not present on this device.", vbCritical, "No MSXML"
    Exit Sub
    End If
    On Error GoTo 0

    'Read in ArcPadPrefs.apx
    Dim blnExists
    blnExists = pXML.Load(strArcPadAPX)

    Dim pNewElement ' Used for new elements that may need to be created alongthe way

    'If it doesn't exist, create one
    If Not blnExists Then
    Set pNewElement = pXML.createNode(1,"ArcPad","")
    Set pXML.documentElement = pNewElement
    Set pNewElement = pXML.createNode(1,"PREFERENCES","")
    pXML.documentElement.appendChild(pNewElement)
    Set pNewElement = Nothing
    End If

    'Get the GPS and PREFERENCES element
    Dim pPREFSElement, pGPSElement
    Set pPREFSElement = pXML.documentElement.selectSingleNode("PREFERENCES")
    Set pGPSElement = pPREFSElement.selectSingleNode("GPS")

    'If the GPS element doesn't exist, create it
    If pGPSElement Is Nothing Then
    Set pNewElement = pXML.createNode(1,"GPS","")
    Set pGPSElement = pPREFSElement.appendChild(pNewElement)
    Set pNewElement = Nothing
    End If

    'Get the AVERAGING element
    Dim pAVGElement
    Set pAVGElement = pGPSElement.selectSingleNode("AVERAGING")

    'If it doesn't exist, create it
    If pAVGElement Is Nothing Then
    Set pNewElement = pXML.createNode(1,"AVERAGING","")
    Set pAVGElement = pGPSElement.appendChild(pNewElement)
    Set pNewElement = Nothing
    End If

    'Set the attributes of the AVERAGING element
    pAVGElement.setAttribute "enabled", "true"
    pAVGElement.setAttribute "point", p_AvgTime

    'Save the changes to ArcPadPrefs.apx
    pXML.Save strArcPadAPX

    'Free resources
    Set pXML = Nothing
    Set pPREFSElement = Nothing
    Set pGPSElement = Nothing
    Set pAVGElement = Nothing

    'Force ArcPad to reload the settings from ArcPadPrefs.apx
    Dim blnSuccess
    blnSuccess = Application.Properties("Load")
    End Sub