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). I have developed the tool in VBscript. Short description what the tool must 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. It's like I can't open the recordset in edit mode. Below you find my source code.
Do you know what I'm doing wrong?

Thanks for helping!


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'
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

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)

    NewPaalID = "P_" & CStr(NewPaalNR)

End If

MsgBox ("New Id: " & NewPaalID)

'go to the new added point

if objDBF.Fields("PAAL_ID").Value ="" Then
    'add the new value
    objDBF.Fields("PAAL_ID").Value = NewPaalID
    MsgBox("Paal_ID " & NewPaalID & " added in Palen.shp")
    MsgBox("No empty feature added")
End If  

Set objDBF = Nothing
End Sub

Having a quick look at your script I would suggest that you break it up into smaller sections.

Rather than continually running the loop to find the highest id, how about you run it once when the map opens and store it as an application variable - application.userproperties(yourID). Then everytime you add a new record (Page OnSetActive event) you have it ready. Then overwrite this application variable to the next id once you have added the feature (Map OnFeatureAdded event).

From your code it is not easily identifiable where you are executing the routine and the actual workflow on feature capture. If you are using the standard point capture tool then ArcPad has already accessed the recordset for you and you could potentially change the way you are communicating with it.

If you are opening the point features' edit form, then wait until the page has been made active and then run your component of the script (IF Statement) - use the Page SetActive event. This way you write your id to the forms control value (txtYourID.value) rather than trying to write to objRS.fields(yourid).value. If you are not using the edit form, then you can always take advantage of the Map.SelectionBookmark. This will help you access the correct row in the recordset.

I have previously written about this on another stack exchange click here question. Also there is an example that comes with ArcPad that in the Tree Register Quick Project template. Have a look at that and see it provides any inspiration.

I hope this helps and please let me know if you need more clarification.

| improve this answer | |
  • Dear Gareth,thanks a lot for your answer! i followed your advise. I have split the code and made some application variables. Everithing works fine until the step I have to insert the new ID in the attribute field of the new feature. Could you give me an example of code how to fix this? Normally, I make a new point feature with the quick capture tool , but if there is another way to do it, thats perfect too! – Kris De Coster Mar 20 '12 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.