Select to view content in your preferred language

VBScript to report XY coordinates

8462
19
07-04-2010 05:09 PM
CarlBeyerhelm
Frequent Contributor
The VBScript listed below returns zeros for both the X and Y coordinates when fired by a point form's OnLoad event.  This should be pretty straight-forward stuff.  What am I missing?

Thanks...

Sub UpdateXY()
'get a reference to the form
Dim pForm
Set pForm = ThisEvent.Object

'get the new point feature's X and Y
Dim X
Dim Y
X = pForm.Fields.Shape.X
Y = pForm.Fields.Shape.Y
pForm.Pages("page1").Controls("X_Coord").Value = X
pForm.Pages("page1").Controls("Y_Coord").Value = Y
End Sub
Tags (3)
0 Kudos
19 Replies
RolfBroch
Frequent Contributor
Seems that the Attachment manager has some problems dealing with zip files created in Windows 7 so I just past the code for the .apl here. The main line is this

<BUTTON onclick="Messagebox EditForm.Fields.Shape.X" name="Button1" x="0" y="54" width="50" height="14" caption="TST" tooltip="" tabstop="true" border="false" alignment="center"/>

<ArcPad>
<LAYER name="Punkter" quickcapture="false">
  <FORMS>
   <EDITFORM name="EDITFORM" caption="Punkter" width="130" height="80" picturepagevisible="true" attributespagevisible="false" symbologypagevisible="true" geographypagevisible="true" required="false">
    <PAGE name="PAGE1" caption="Punkt">
     <LABEL name="LABEL1" x="1" y="1" width="43" height="12" caption="Navn" tooltip="" border="false"/>
     <EDIT name="NAVN" x="45" y="1" width="84" height="12" defaultvalue="" tooltip="" tabstop="true" border="true" field="NAVN"/>
     <LABEL name="LABEL2" x="1" y="14" width="43" height="12" caption="Kategori" tooltip="" border="false"/>
     <SYMBOLOGYFIELD name="KATEGORI" x="45" y="14" width="84" height="12" defaultvalue="" listtable="" listvaluefield="" listtextfield="" tooltip="" tabstop="true" border="true" limittolist="false" field="KATEGORI"/>
     <LABEL name="LABEL3" x="1" y="27" width="43" height="14" caption="Dato" tooltip="" border="false"/>
     <DATETIME name="DATO" x="45" y="27" width="84" height="14" defaultvalue="" tooltip="" tabstop="true" border="true" field="DATO" allownulls="false"/>
     <LABEL name="LABEL4" x="1" y="42" width="43" height="12" caption="Kommentar" tooltip="" border="false"/>
     <EDIT name="KOMMENTAR" x="45" y="42" width="84" height="36" defaultvalue="" tooltip="" tabstop="true" border="true" field="KOMMENTAR" multiline="true"/>
     <BUTTON onclick="Messagebox EditForm.Fields.Shape.X" name="Button1" x="0" y="54" width="50" height="14" caption="TST" tooltip="" tabstop="true" border="false" alignment="center"/>
    </PAGE>
    <PICTUREPAGE>
     <PICTUREFIELD field="Foto"/>
    </PICTUREPAGE>
   </EDITFORM>
  </FORMS>
  <METADATA>
   <COMMENTS>QuickProject : Punkter</COMMENTS>
  </METADATA>
  <HYPERLINK field="Foto"/>
  <SYMBOLOGY>
   <SIMPLELABELRENDERER field="Navn" visible="true"/>
   <VALUEMAPRENDERER lookupfield="Kategori">
    <EXACT label="Kategori 1" value="1" quickcapture="true">
     <SIMPLEMARKERSYMBOL type="circle" color="Red" width="5" outlinewidth="1"/>
    </EXACT>
    <EXACT label="Kategori 2" value="2" quickcapture="true">
     <SIMPLEMARKERSYMBOL type="square" color="GreenYellow" width="5" outlinewidth="1"/>
    </EXACT>
    <EXACT label="Kategori 3" value="3" quickcapture="true">
     <SIMPLEMARKERSYMBOL type="star" color="LightskyBlue" width="5" outlinewidth="1"/>
    </EXACT>
    <EXACT label="Kategori 4" value="4">
     <SIMPLEMARKERSYMBOL type="triangle" color="Gold" width="5" outlinewidth="1"/>
    </EXACT>
    <EXACT label="Kategori 5" value="5">
     <SIMPLEMARKERSYMBOL type="diamond" color="MediumOrchid" width="5" outlinewidth="1"/>
    </EXACT>
    <OTHER label="Andre kategorier">
     <SIMPLEMARKERSYMBOL type="x" color="Black" width="5" outlinewidth="1"/>
    </OTHER>
   </VALUEMAPRENDERER>
  </SYMBOLOGY>
</LAYER>
</ArcPad>
0 Kudos
CarlBeyerhelm
Frequent Contributor
Progress!  The code works nicely when the form is referenced directly as "EditForm" (as you have done) instead of referencing it (as I was doing) as:

Dim pForm
Set pForm = ThisEvent.Object

I'll experiment some more and report back in several days.

Thank you!
0 Kudos
CarlBeyerhelm
Frequent Contributor
A new wrinkle has developed.

The code MessageBox EditForm.Fields.Shape.X returns a legitimate X value when called from the OnLoad event of a point shapefile's form .apl that was created as a QuickProject.

However, the identical code called from the OnLoad event of an AXF point layer's form returns a zero.

Perhaps shapefiles and AXF layers don't behave the same way?
0 Kudos
RolfBroch
Frequent Contributor
They should behave the same way.

Have you tried to attach the code to a command button as in my example so you can run the code after the form has loaded?
0 Kudos
RolfBroch
Frequent Contributor
when you deal with the datasource through the editform they should behave the same. Have you tried to run the code from a button in the editform instead of the onload event?
0 Kudos
CarlBeyerhelm
Frequent Contributor
I created a QuickProject, and an AXF checkout.  I added a "Get X Coord" button to each of the edit forms.  The button's On Click event calls:

MessageBox "The X coord is " & EditForm.Fields.Shape.X

The AXF form returns a zero.  The QuickProject form returns a legitimate X coord.  See attached images.

I don't know why the two forms produce a different result even though their code is identical.
0 Kudos
MichaelFraser
New Contributor
Carl, did you ever figure this one out? I am encoutering the same problem.  Funny thing is that the code worked just fine in ArcPad 7.1.1, but now in ArcPad 10 I get 0 for the Shape.X and Shape.Y values.
0 Kudos
CarlBeyerhelm
Frequent Contributor
No, I was unable to work it out.  The two forms, one running against a shapefile and the other running against an AXF file, produce different results even though their code is identical.  It is mysterious and disappointing...
0 Kudos
RolfBroch
Frequent Contributor
Log it with ESRI support to hear why.
0 Kudos
GregoryElwood
Emerging Contributor
Did anyone ever hear from ESRI on this?

I have two scripts I'm working (hacking!) on, one that allows the user to click on a custom tool and place a point anywhere they want, with maybe a form to populate the XYZ values if the user wants to after the point has been created. The other allows the user to tap and have the GPS position populate the XYZ of the created point. I'd really like some simple, easy to plug-in lines of VBS script to just populate the X, Y and Z attribute fields of the point shapefile with the point's current values. I don't need the values to be from a pending point, as saving the points is not a problem after they have been created. The many forum posts and script samples have been helpful, especially since I'm new to all of this, but a simple answer that fits my VBS skill level still eludes me.

Thanks for bearing with me (and, apparently, others) as I learn VBS for ArcPad10.

Gregory
0 Kudos