Programming automating tool in VBscipt in ArcPad

600
1
03-19-2012 05:06 AM
KrisDe_Coster
New Contributor
Hello,

I am working on an automating tool for ArcPad for inventory issues on our mobile GIS machine (Trimble GeoXH - Geoexplorer 2008 series - Windows mobile 6.1 and Arcdap 10.0.3) in VBscript. Short description of what the tool is supposed to do:
We have a point shapefile in Arcpad. Everytime when we manually add a point, it automaticaly counts the new ID by clicking on a button in the toolbar. The new ID is the last ID + 1. I succeeded already in looping through the attributes, finding the last ID and calculating a new ID. 😮 However, I can't add the new calculated ID for the added point in the attribute table :mad: ... It's like I can't open the recordset in edit mode.

Below you find my source code.

Anybody kows what I'm doing wrong? Thanks for helping me!
Kris

My Sourcecode:
Sub Test
Dim objDBF, strLaatstePaalID, NewPaalNR, NewPaalID, Nummer, PaalCode
Numbre = 0
Set objLyr = Map.Layers("Palen")
Set objDBF = objLyr.Records
'Look for record with the highest ID
'ID is text format like 'P_00450'
objDBF.MoveFirst
Do Until objDBF.EOF
  PaalCode = objDBF.Fields("PAAL_ID").Value
  If PaalCode <> "" Then 'the new added point (which is the last) has no value in the ID
   If Int(Right(PaalCode,(Len(PaalCode)-2)))>Numbre Then
    'Make an integer of the text code
    Numbre = Int(Right(PaalCode,(Len(PaalCode)-2)))
   End If
  End If
  objDBF.MoveNext
Loop

NewPaalNR = Numbre + 1
 
'Maak een nieuw text ID with the new numbre
    If NewPaalNR < 10 Then
        NewPaalID = "P_0000" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 100 Then
        NewPaalID = "P_000" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 1000 Then
        NewPaalID = "P_00" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 10000 Then
        NewPaalID = "P_0" & CStr(NewPaalNR)

    Else
        NewPaalID = "P_" & CStr(NewPaalNR)
 
End If
 
MsgBox ("New Id: " & NewPaalID)

'go to the new added point
objDBF.MoveLast

if objDBF.Fields("PAAL_ID").Value ="" Then
  'add the new value
  objDBF.Fields("PAAL_ID").Value = NewPaalID
  objDBF.Update
  MsgBox("Paal_ID " & NewPaalID & " added in Palen.shp")
Else
  MsgBox("No empty feature added")
End If
 
Set objDBF = Nothing
End Sub
Tags (3)
0 Kudos
1 Reply
EricHajek1
Occasional Contributor
What event are you calling this Sub from? It may not let you alter the value if it's during the OnUnload event of the form. If that's where it is being called, you might try the OnOK event.

Also, when I looked up the Layer object in the "Customizing ArcPad" help, and then clicked on the Records Property, it indicates that it's read only, so it may not be possible to use the Records object to do this. It is possible to programmatically update attributes outside of the edit form, but I haven't done this for shapefiles (have done it with SQL for AXF files) so I'm not sure of the exact methods used. You might try doing this while the Edit Form is displayed and just having a text box whose value you update with the code. Then the value will get saved along with the rest of the form's values. If it were me I'd go this route.

Hope this helps,
Eric
0 Kudos