Thanks for the replies, I ended up rewriting the script so it checks if a form is open and if it is it writes the GPS data to a custom form page "GPS" which I'm adding to all my edit forms, otherwise it assumes I'm moving an existing point and uses the selected record approach. The code is really inefficient and I ran into some other issues but it's working at a basic level.
Rebecca's reply mentioning Application.UserProperties that I hadn't discovered yet gives me a whole other way to approach this that I'll attempt later when I have some time.
<?xml version="1.0" encoding="UTF-8"?>
<ArcPad compiled="true">
<APPLET name="GPS_Metadata2">
<SYSTEMOBJECTS>
<GPS onAverageStop="Call GPSMetadata"/>
</SYSTEMOBJECTS>
</APPLET>
<SCRIPT language="VBScript">
Option Explicit
Sub GPSMetadata
' Main routine to add GPS metadata from the NMEA string to edit layers configured with GPS attributes.
' Set variables
Dim editPointLayer, editLineLayer
'Get edit layers
Set editPointLayer = Map.EditLayer(1)
Set editLineLayer = Map.EditLayer(2)
'If there is an edit point layer, add/update GPS metadata if EDITFORM open or selected feature
If Not (editPointLayer Is Nothing) Then
' If the EDITFORM is open, assume creating a new point and fill in form and update GPS fields values
If editPointLayer.Forms("EDITFORM").Mode = 3 Then
Call FillGPSForm(editPointLayer)
' If EDITFORM is not open but the edit point layer has a feature currently selected update GPS fields values
ElseIf editPointLayer.Name = Map.SelectionLayer.Name Then
' Application.StatusBar.Text = "The edit point layer matches the selection layer"
Call UpdateGPSFields(editPointLayer)
End If
End If
'If there is an edit line layer, add/update GPS metadata if EDITFORM open or selected feature
If Not (editLineLayer Is Nothing) Then
' This won't work because form isn't open until after drawing a new polyline
If editLineLayer.Forms("EDITFORM").Mode = 3 Then
Call FillGPSForm(editLineLayer)
' If EDITFORM is not open but the edit line layer has a feature currently selected update GPS fields values
ElseIf edit LineLayer.Name = Map.SelectionLayer.Name Then
' Application.StatusBar.Text = "The edit line layer matches the selection layer"
Call UpdateGPSFields(editLineLayer)
End If
End If
End Sub
Sub FillGPSForm(editLayer)
' Populates GPS attributes values and the open form
' Use when creating a new feature and the EDITFORM is open
' Testing showed values not updating if attributes are on the active form page, hence the overkill with forms and values
' Define variables
Dim f, fCount
For Each f in editLayer.Forms("EDITFORM").Fields
Select Case Ucase(f.name)
Case "GPS_QUAL"
' Application.StatusBar.Text = GPS.Properties("QUALITY")
f.Value = GPS.Properties("QUALITY")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_QUAL").Value = GPS.Properties("QUALITY")
fCount = fCount + 1
Case "GPS_SATS"
' Application.StatusBar.Text = GPS.Properties("SATS_USED")
f.Value = GPS.Properties("SATS_USED")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_SATS").Value = GPS.Properties("SATS_USED")
fCount = fCount + 1
Case "GPS_X"
f.Value = GPS.x
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_X").Value = GPS.x
fCount = fCount + 1
Case "GPS_Y"
f.Value = GPS.y
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_Y").Value = GPS.y
fCount = fCount + 1
Case "GPS_Z"
f.Value = GPS.Z
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_Z").Value = GPS.Z
fCount = fCount + 1
Case "GPS_LAT"
f.Value = GPS.Latitude
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_LAT").Value = GPS.Latitude
fCount = fCount + 1
Case "GPS_LONG"
f.Value = GPS.Longitude
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_LONG").Value = GPS.Longitude
fCount = fCount + 1
Case "GPS_ALT"
f.Value = GPS.Altitude
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_ALT").Value = GPS.Altitude
fCount = fCount + 1
Case "GPS_PDOP"
f.Value = GPS.Properties("PDOP")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_PDOP").Value = GPS.Properties("PDOP")
fCount = fCount + 1
Case "GPS_HDOP"
f.Value = GPS.Properties("HDOP")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_HDOP").Value = GPS.Properties("HDOP")
fCount = fCount + 1
Case "GPS_VDOP"
f.Value = GPS.Properties("VDOP")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_VDOP").Value = GPS.Properties("VDOP")
fCount = fCount + 1
Case "GPS_DGPS"
f.Value = GPS.Properties("DIFF_ID")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_DGPS").Value = GPS.Properties("DIFF_ID")
fCount = fCount + 1
Case "GPS_DIFF"
f.Value = GPS.Properties("DIFF_AGE")
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_DIFF").Value = GPS.Properties("DIFF_AGE")
fCount = fCount + 1
Case "GPS_TIME"
f.Value = FormatDateTime(GPS.Properties ("UTC"), vbLongTime)
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_TIME").Value = FormatDateTime(GPS.Properties ("UTC"), vbLongTime)
fCount = fCount + 1
Case "GPS_DATE"
f.Value = FormatDateTime(GPS.Properties ("UTC"), vbShortDate)
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_DATE").Value = FormatDateTime(GPS.Properties ("UTC"), vbShortDate)
fCount = fCount + 1
Case "GPS_T_LOC"
f.Value = FormatDateTime(Now, vbLongTime)
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_T_LOC").Value = FormatDateTime(Now, vbLongTime)
fCount = fCount + 1
Case "GPS_D_LOC"
f.Value = FormatDateTime(Now, vbShortDate)
editLayer.Forms("EDITFORM").Pages.Item("GPS").Controls("txtGPS_D_LOC").Value = FormatDateTime(Now, vbShortDate)
fCount = fCount + 1
End Select
Next
End Sub
Sub UpdateGPSFields(selLayer)
' Updates GPS attributes for the selected editable feature
' Use when updating the position of an existing feature with GPS ("move to GPS")
' Define variables
Dim f, fCount, objRS
' Get the currently selected record from the edit layer
Set objRS = selLayer.Records
objRS.Bookmark = Map.SelectionBookmark
For Each f in objRS.Fields
Select Case Ucase(f.name)
Case "GPS_QUAL"
' Application.StatusBar.Text = GPS.Properties("QUALITY")
f.Value = GPS.Properties("QUALITY")
fCount = fCount + 1
Case "GPS_SATS"
' Application.StatusBar.Text = GPS.Properties("SATS_USED")
f.Value = GPS.Properties("SATS_USED")
fCount = fCount + 1
Case "GPS_X"
f.Value = GPS.x
fCount = fCount + 1
Case "GPS_Y"
f.Value = GPS.y
fCount = fCount + 1
Case "GPS_Z"
f.Value = GPS.Z
fCount = fCount + 1
Case "GPS_LAT"
f.Value = GPS.Latitude
fCount = fCount + 1
Case "GPS_LONG"
f.Value = GPS.Longitude
fCount = fCount + 1
Case "GPS_ALT"
f.Value = GPS.Altitude
fCount = fCount + 1
Case "GPS_PDOP"
f.Value = GPS.Properties("PDOP")
fCount = fCount + 1
Case "GPS_HDOP"
f.Value = GPS.Properties("HDOP")
fCount = fCount + 1
Case "GPS_VDOP"
f.Value = GPS.Properties("VDOP")
fCount = fCount + 1
Case "GPS_DGPS"
f.Value = GPS.Properties("DIFF_ID")
fCount = fCount + 1
Case "GPS_DIFF"
f.Value = GPS.Properties("DIFF_AGE")
fCount = fCount + 1
Case "GPS_TIME"
f.Value = FormatDateTime(GPS.Properties ("UTC"), vbLongTime)
fCount = fCount + 1
Case "GPS_DATE"
f.Value = FormatDateTime(GPS.Properties ("UTC"), vbShortDate)
fCount = fCount + 1
Case "GPS_T_LOC"
f.Value = FormatDateTime(Now, vbLongTime)
fCount = fCount + 1
Case "GPS_D_LOC"
f.Value = FormatDateTime(Now, vbShortDate)
fCount = fCount + 1
End Select
Next
' Update the record
objRS.Update
End Sub
</SCRIPT>
</ArcPad>