Script Subtracting Fields to Populate Another Field in ArcPad 10

5327
8
02-22-2011 07:16 AM
jeffclonts
New Contributor
Hello, I am new to ArcPad/Studio. I am running ArcPad 10 and I am looking to do the following. I have customized a form that our field crews will deploy to collect groundwater monitoring information. In an effort to minimize user input I wanted to come up with a script that would auto populate a field based on the input of another field. An example is as follows:

The crew member would enter a value into the field "GW Depth". The next field on the form is "Well Depth". This field is read only and already has a value associated with it. The next field on the form is "Water Column Thickness". "Water Column Thickness" is derived by subtracting "Groundwater Depth" from "Well Depth". I would like this field to auto populate once the crew member enters a value for "Groundwater Depth". I searched through ArcPad discussion forums and found a few scripts that may be what I am looking for. Below is my first stab at it:

Sub SumFunction
Dim objEditForm
Set objEditForm = Application.Forms("EDITFORM").Pages("GWPage1").Controls("WaterColumnThickness")

objEditForm("WaterColumnThickness") = objEditForm("GWDepth").Value - objEditForm("WellDepth").Value
End Sub

From what I understand I open up <SCRIPT> in ArcPad Studio and enter the code above (no idea if it is even close to being correct). I would then go into the Events tab for the Water Column Thickness field and create an event under "onchange" that states: Call SumFunction.

Once saved, I open the form in ArcPad and enter a value for GW depth. The Water Column Thickness field does not populate. Again, I am very new at Scripting/ArcPad, so any help or direction would be greatly appreciated.

Thanks,

JC
Tags (3)
0 Kudos
8 Replies
jeffclonts
New Contributor
After staring at it long enough I have solved my issue. The code that worked is attached.

Set objControl = ThisEvent.Object
    Set objPage = ThisEvent.Object.Parent  

      GWDepth = objControl.Value 
      WaterColumnThickness = objPage.Controls("txtWell_Dep_TOC").Value - GWDepth
      objPage.Controls("txtWat_Column").Value = WaterColumnThickness

End Sub

Thanks
0 Kudos
CharlesHuxtable
New Contributor
Hi Jeff, that's really helpful as  I'm trying to do something similar. I want to add the contents of a number of fields and autopopulate a "Tally" field with the sum of these fields. I used your code, but when I substituted "+" for "-" it doesn't work. eg. If I enter "100" for the well depth and "20" for the GW depth, the water column thickness field is autopopulated with "10020". I'm not sure what he problem is - it appears to be adding the text string rather than the numerical values. The code  (called from the Onchange event in the GW depth field) I used was:
Sub SumFunction
Set objControl= ThisEvent.Object
Set objPage= ThisEvent.Object.Parent
GWDepth= objControl.Value
WaterColumnThickness= objPage.Controls("TxtWell_Dep_TOC").Value + GWDepth
objPage.Controls("TxtWat_Column").Value= WaterColumnThickness
End Sub

Any ideas?
0 Kudos
RuiGe
by Esri Contributor
Esri Contributor
Hi,
The value of an Editbox control is string.
It might help if you use the field property of the controls to get the numbers

GWDepth= objControl.Field.Value
WaterColumnThickness= objPage.Controls("TxtWell_Dep_TOC").Field.Value + GWDepth




Hi Jeff, that's really helpful as  I'm trying to do something similar. I want to add the contents of a number of fields and autopopulate a "Tally" field with the sum of these fields. I used your code, but when I substituted "+" for "-" it doesn't work. eg. If I enter "100" for the well depth and "20" for the GW depth, the water column thickness field is autopopulated with "10020". I'm not sure what he problem is - it appears to be adding the text string rather than the numerical values. The code  (called from the Onchange event in the GW depth field) I used was:
Sub SumFunction
Set objControl= ThisEvent.Object
Set objPage= ThisEvent.Object.Parent
GWDepth= objControl.Value
WaterColumnThickness= objPage.Controls("TxtWell_Dep_TOC").Value + GWDepth
objPage.Controls("TxtWat_Column").Value= WaterColumnThickness
End Sub

Any ideas?
0 Kudos
CharlesHuxtable
New Contributor
Hi GE,
Tried that, but got following error message :
"Microsoft VBScript runtime error
Object Required: ObjControl.Field
[Line: 299, Col: 2]
Source Text Unavailable"
0 Kudos
jeffclonts
New Contributor
Hey Chuxtable
It seems I missed the first few lines of code when I pasted it into the message. Sorry about that. Hopefully it resolves your issue.

Sub SumFunction 
  Dim objControl, objPage, GWDepth, WaterColumnThickness  
    Set objControl = ThisEvent.Object
    Set objPage = ThisEvent.Object.Parent  
      GWDepth = objControl.Value 
      WaterColumnThickness = objPage.Controls("txtWell_Dep_TOC").Value - GWDepth
      objPage.Controls("txtWat_Column").Value = WaterColumnThickness
End Sub

I have also added some additional code to populate a few more fields on my form. Hopefully you can use these as well.

Sub SumFunction 

  Dim objControl, objPage, GWDepth, WaterColumnThickness, GroundwaterElevation, CasingVolume
   
    Set objControl = ThisEvent.Object
    Set objPage = ThisEvent.Object.Parent  

      'Calculates water column thickness
      GWDepth = objControl.Value 
      WaterColumnThickness = objPage.Controls("txtWell_Dep_TOC").Value - GWDepth
      objPage.Controls("txtWat_Column").Value = WaterColumnThickness

      'Calculates groundwater elevation
      GWDepth = objControl.Value 
      GroundwaterElevation = objPage.Controls("txtWellElevation").Value - GWDepth
      objPage.Controls("txtGWElevation").Value = GroundwaterElevation

      'Calculates casing volume based on well casing diameter
      GWDepth = objControl.Value
      If objPage.Controls("txtCasDiameter").Value = 1 then
      CasingVolume = objPage.Controls("txtWat_Column").Value * 0.04
      Elseif objPage.Controls("txtCasDiameter").Value = 2 then
      CasingVolume = objPage.Controls("txtWat_Column").Value * 0.16
      Elseif objPage.Controls("txtCasDiameter").Value = 4 then
      CasingVolume = objPage.Controls("txtWat_Column").Value * 0.65
      Elseif objPage.Controls("txtCasDiameter").Value = 6 then
      CasingVolume = objPage.Controls("txtWat_Column").Value * 1.47
      Elseif objPage.Controls("txtCasDiameter").Value = 8 then
      CasingVolume = objPage.Controls("txtWat_Column").Value * 10.1
      End if
      objPage.Controls("txtCasVolume").Value = CasingVolume

     
End Sub

These are all run in the onchange event in my GW Depth control

later,
JC
0 Kudos
RuiGe
by Esri Contributor
Esri Contributor
I took a second look at the script -- you are using the "onchange" event on the GW Depth field so the "Field" property might not be useful in this case.

The "+" is actully concatenating the two strings instead of adding two numbers together. So the simple  conversion I can think of for this case is :

GWDepth= objControl.Value
objPage.Controls("TxtWat_Column").Value = CDbl(objPage.Controls("TxtWell_Dep_TOC").Value) + CDbl (GWDepth)


Hi,
The value of an Editbox control is string.
It might help if you use the field property of the controls to get the numbers

GWDepth= objControl.Field.Value
WaterColumnThickness= objPage.Controls("TxtWell_Dep_TOC").Field.Value + GWDepth
0 Kudos
CharlesHuxtable
New Contributor
Great - that worked! Thanks Rui, and thanks Jeff for the additional script
0 Kudos
AmandaSkelding
New Contributor II
Great - that worked! Thanks Rui, and thanks Jeff for the additional script


Hi Charles;  Thanks for the information in this thread. However, I am unsure just where to put the code in Arcstudio. Is it under the NewVBScript file?

Thanks.
0 Kudos