Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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!

Kris

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

share|improve this question
add comment

1 Answer

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.

Cheers,

Gareth

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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