The ArcPad Team Blog

Unofficial stuff from the team behind the World's leading mobile GIS platform

Wednesday, September 30, 2009

Code Review - History Tool from ArcWatch

We just wanted to say thanks to Mel Yuanhang Meng for posting an excellent, practical solution using ArcPad to increase effiency in building surveys. After reading through the article we noticed that the sample was written using shapefiles. Come on Mel, don’t you know that “the AXFs are the future” (didn’t Michael Jackson sing something about that?).

So after creating an AXF from the sample data, I copied the editform from the .APL and pasted it into the AXF Parcel Layer APL. Then I created a jscript file for the AXF and copied the code straight in and added the script to the event. Everything worked as it should, but upon further investigation we noticed some inconsistencies. The code itself works great if you are editing a feature that has never been surveyed before, however if you did want to edit a feature that already has attributes, then the code will run but it may not populate all the fields (have something set to “good” or “yes” on the feature you are editing to see what I mean).

The reason I bring this up is that if, like all good ArcPad hacks, you will probably take this code and try and implement it yourself but in a slightly different manner. For example you may want to use this on a related tables form that you have created as the out of the box repeated attributes tool doesn’t work on them – yet. So what’s the fix I hear you ask. Well quite exquisitely simple. There is a line of code asking an “IF” statement: if (ctls.Item(j).ListIndex). What do you notice about that line of code?

That’s right, the question isn’t asking for a proper answer such as “if ( != Gareth)”. Therefore if there is a value in the ListIndex it cannot compute and finishes the routine. So then, the answer is, get the question asking for a value by changing it to: if (ctls.Item(j).ListIndex != null). Now run the code in that same example and you will see all the values change as they would on a new survey.

Hopefully you find this of use in upcoming projects and thank you again to Mel for publishing his content and sharing it - excellent to see people making cool customizations that help improve people’s daily routine. So don’t be shy! Post your code on ArcScripts so all can benefit.

A note from our sponsor:

We noticed also that at the very beginning of the fill_form function that there is a variable called pgs and it’s reference was ThisEvent.Object.Parent.Parent.Pages; I would just like to add that this works fine but if anyone is going to implement this, you may like to read the Customizing ArcPad Help documentation (nice plug) whereby you reference the object and the form separately. We feel it would be easier to read and also you can create other controls based on the orignial control (see below).

Dim theControl, allControls, theForm
Set theControl = ThisEvent.
Set allControls = theControl.Parent.Controls
Set theForm = theControl.Parent.Parent

You can now easily get or set the values of other controls on the page, as well as the control responding to the event, as in the following example:

Dim value1, value2, value3
value1 = theControl.Value
value2 = allControls("TextBox1").Value
value3 = allControls("ComboBox1").Value

Happy Mapping!


Post a Comment

<< Home