Select to view content in your preferred language

Auto-populate field depending on value of other fields - ArcPad

9341
20
Jump to solution
12-02-2014 08:38 AM
charlesprowse
Deactivated User

I need to collect data for structures, part of which is a score-based risk assessment.

The risk assessment has three selectors, the total of which give the overall score.

I would like to have a totals field which adds up the values of the three selectors, is this possible and if so how do I achieve it?

I am able to create layers, add attributes and use arcpad studio to create a form but beyond that I am stuck.

The three selectors are:

Target Value

Size (of structure or part of)

Failure Risk

If anyone is able to provide any help whatsoever I would be extremely grateful.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
MosquitoGIS
Frequent Contributor

Alright, I threw this together pretty quick, but it should give you some basics to get started on and give you the basic ideas on how to work with vbscript in ArcPad.

I created a simple form that with the four fields.  Target, Size and Failure and RoH.  I then Just gave each (Minus RoH) a drop down with High, Medium, and Low per your example.  I have used simply a point Shapefile in mine, but did not create a field for RoH.  And in order for it it to store the RoH you would simply have to create a new field in my shapefile and just attach the field I have the on the form to the field of the Shapefile.

In the example I used, it stores the text info in the database (High, medium, low), but if you decide to do numbers, that should be fairly easily to figure out and maybe even simplify.

In my code, I showed how to pull data from form, place data in forms, and even how to display that data in a msgbox (Including one with a second line in the msgbox in case you ever need to do that in the future).  It also show examples of if/then statements and case statements.  I think with all that, it should be a very helpful set of tools to quickly look at and at least get you started.  Hopefully that helps.  If you get caught up in anything or have any additional questions, let me know, and I will do what I can to help.

Anyway, I will post the code here as well as attach the files I created to work with including the Shapefile (Which I never tested if it stored, but it should), my .apl (Form), and the vbscript along with that.  I also in my vbscript, tried to give instructions on what each piece of code is doing.

.Apl (Form File) Code:

<?xml version="1.0" encoding="UTF-8"?>

<ArcPad>

  <LAYER name="RiskT">

  <SYMBOLOGY>

  <SIMPLELABELRENDERER visible="false" field="Target">

  <TEXTSYMBOL angle="0" fontcolor="0,0,0" font="Arial" fontsize="8" horzalignment="left" vertalignment="bottom" rtl="false">

  </TEXTSYMBOL>

  </SIMPLELABELRENDERER>

  <SIMPLERENDERER label="">

  <SIMPLEMARKERSYMBOL angle="0" width="4" color="0,166,116" type="circle" outline="0,0,0" outlinewidth="1" outlinetype="solid">

  </SIMPLEMARKERSYMBOL>

  </SIMPLERENDERER>

  </SYMBOLOGY>

  <FORMS>

  <EDITFORM name="RiskT" caption="RiskT" width="130" height="130" attributespagevisible="false" picturepagevisible="true" symbologypagevisible="true" geographypagevisible="true" required="false">

  <PAGE name="page1" caption="Page 1">

  <LABEL name="lblTarget" x="2" y="18" width="60" height="12" caption="Target" tooltip="" border="false">

  </LABEL>

  <LABEL name="lblSize" x="2" y="33" width="60" height="12" caption="Size" tooltip="" border="false">

  </LABEL>

  <LABEL name="lblFailure" x="2" y="48" width="60" height="12" caption="Failure" tooltip="" border="false">

  </LABEL>

  <COMBOBOX name="CboTarget" x="64" y="17" width="63" height="13" defaultvalue="" listtable="" listvaluefield="" listtextfield="" tooltip="" tabstop="true" border="false" sip="false" sort="false" field="TARGET">

  <LISTITEM value="High" text="High"/>

  <LISTITEM value="Medium" text="Medium"/>

  <LISTITEM value="Low" text="Low"/>

  </COMBOBOX>

  <COMBOBOX name="CboSize" x="64" y="32" width="63" height="100" defaultvalue="" listtable="" listvaluefield="" listtextfield="" tooltip="" tabstop="true" border="false" sip="false" sort="false" field="SIZE">

  <LISTITEM value="High" text="High"/>

  <LISTITEM value="Medium" text="Medium"/>

  <LISTITEM value="Low" text="Low"/>

  </COMBOBOX>

  <COMBOBOX name="CboFailure" x="64" y="47" width="63" height="100" defaultvalue="" listtable="" listvaluefield="" listtextfield="" tooltip="" tabstop="true" border="false" sip="false" sort="false" field="FAILURE">

  <LISTITEM value="High" text="High"/>

  <LISTITEM value="Medium" text="Medium"/>

  <LISTITEM value="Low" text="Low"/>

  </COMBOBOX>

  <LABEL name="LblRoH" x="3" y="63" width="50" height="10" caption="RoH" tooltip="" group="true" border="false"/>

  <EDIT name="TxtRoH" x="64" y="62" width="63" height="12" defaultvalue="" tooltip="" tabstop="true" border="true" readonly="true" sip="false" field=""/>

  <BUTTON name="BtnRoHSum" x="39" y="89" width="50" height="14" onclick="Call SumFunction" caption="RoH Sum" tooltip="" tabstop="true" border="false" alignment="center"/>

  </PAGE>

  </EDITFORM>

  <QUERYFORM name="QUERYFORM" caption="Query Form" width="130" height="130">

  <PAGE name="page1" caption="RiskT Query (Page 1)">

  <LABEL name="lblId" x="2" y="3" width="60" height="12" tabstop="false" caption="Id">

  </LABEL>

  <EDIT name="txtId" x="64" y="2" width="60" height="12" tabstop="true" required="true" readonly="false" field="Id">

  </EDIT>

  <LABEL name="lblTarget" x="2" y="18" width="60" height="12" tabstop="false" caption="Target">

  </LABEL>

  <EDIT name="txtTarget" x="64" y="17" width="60" height="12" tabstop="true" required="true" readonly="false" field="Target">

  </EDIT>

  <LABEL name="lblSize" x="2" y="33" width="60" height="12" tabstop="false" caption="Size">

  </LABEL>

  <EDIT name="txtSize" x="64" y="32" width="60" height="12" tabstop="true" required="true" readonly="false" field="Size">

  </EDIT>

  <LABEL name="lblFailure" x="2" y="48" width="60" height="12" tabstop="false" caption="Failure">

  </LABEL>

  <EDIT name="txtFailure" x="64" y="47" width="60" height="12" tabstop="true" required="true" readonly="false" field="Failure">

  </EDIT>

  </PAGE>

  </QUERYFORM>

  </FORMS>

  </LAYER>

  <SCRIPT src="RiskT.vbs"/>

</ArcPad>

VBScript:

Option Explicit

'Create Used Variables

Dim RoHV, TxtTargetV, TxtSizeV, TxtFailureV, ValTarget, ValSize, ValFailure

Sub SumFunction

'Set my number Value Varaibles to 0

  RoHV = 0

  ValTarget = 0

  ValSize = 0

  ValFailure = 0

' Set my text variables to whatever info is on page1 of the form in that particular name of text field

  Set TxtTargetV = EDITFORM.Pages.Item("page1").Controls.Item("CboTarget")

  Set TxtSizeV = EDITFORM.Pages.Item("page1").Controls.Item("CboSize")

  Set TxtFailureV = EDITFORM.Pages.Item("page1").Controls.Item("CboFailure")

'Using case selectment, Set the Number Varaible for Target to a number based on what was in the "Target" field

  Select Case TxtTargetV

    Case "High"

      ValTarget = 3

    Case "Medium"

      ValTarget = 2

    Case "Low"

      ValTarget = 1

    Case Else

      ValTarget = 0

  End Select

'Using case selectment, Set the Number Varaible for Size to a number based on what was in the "Size" field

  Select Case TxtSizeV

    Case "High"

      ValSize = 3

    Case "Medium"

      ValSize = 2

    Case "Low"

      ValSize = 1

    Case Else

      ValSize = 0

  End Select

'Doing the same thing above for the "Failure" Field, just using If/Then Statements to introduce to those

  If TxtFailureV = "High" then

    ValFailure = 3

  End if

  If TxtFailureV = "Medium" then

    ValFailure = 2

  End if

  If TxtFailureV = "Low" then

    ValFailure = 1

  End if

' Calculate out what the RoH would be

  RoHV = ValTarget + ValSize + ValFailure

'Display the RoH in the RoH field on the form

'  EDITFORM.Pages.Item("page1").Controls.Item("TxtRoH") = RoHV

  EDITFORM.Pages("page1").Controls("TxtRoH").Value = RoHV

'Display the RoH in a message box to show an example of message boxes.

  msgbox "RoH: " & RoHV & " Number." & vbCrlf & vbCrlf & _

         "Have a Great Day!", apOKOnly, "RoH Number Title"

End Sub

View solution in original post

0 Kudos
20 Replies
JorgeOrellana
Deactivated User

You would have to write a VB script or JavaScript for your forms in order to do this. I haven't programmed for ArcPad in quite some time but there should be plenty of documentation on how to do this.

Here is a sample of someone that asked a similar question

Script Subtracting Fields to Populate Another Field in ArcPad 10

0 Kudos
charlesprowse
Deactivated User

Jorge

Many thanks for taking the time to respond to my query. I had read through the post regards subtracting fields and even attempted to make it work but I had no success unfortunately.

I think I need an idiots guide!

0 Kudos
JorgeOrellana
Deactivated User

Do you have much experience with Scripting?

I suggest taking quick read at this PDF that goes over some basic Arcpad and VBScript

http://arcscripts.esri.com/data/as15207.pdf

Also try downloading  these scripts

Basic ArcPad Script Examples

They can help you understand a little bit more of how to do things. Sorry I'm not of much help with the actual coding, at this point it's been a long time since I last coded but I know I used those two resources when I was first starting to code.

Cheers

0 Kudos
charlesprowse
Deactivated User

Jorge

Many thanks for the links. I had found them before but found them above my level of understanding. Nevertheless I have made some (unfortunately fruitless) attempts - see reply to Devin below.

0 Kudos
MosquitoGIS
Frequent Contributor

Hey Charles,

If I am gathering correctly what you are attempting to do, it sounds like a semi-simple thing.  If you post what you have available for code, both in your vbscript and what you have it attached to (i am assuming a form), I may be able to help clean up what you currently have.  I have been doing a bit of scripting in the last while, and may know enough to help.

0 Kudos
charlesprowse
Deactivated User

Devin

Thanks for your offer of help. I have read through the articles suggested by Jorge above and have come up with the following attempt but with no joy no matter how many adjustments I make.

Sub SumFunction 

Dim objControl, objPage, RoH

Set objControl = ThisEvent.Object

Set objPage = ThisEvent.Object.Parent

RoH = objPage.Controls("Target").Field.Value + objPage.Controls("Size").Field.Value + objPage.Controls("Failure").Field.Value

End Sub

Because I am trying to grasp the theory of form customization at present I have only made a simple shp layer and associated form with the attributes of: Target; Size; Failure & RoH (Risk of Harm).

What I ultimately would like to achieve is for the form fields of Target, Size & Failure to be comboboxes with menus to select from (ideally as text of High, medium, low with a numerical association if possible) with the total sum of those three fields being displayed in the RoH field on the form.

I have managed to achieve similar function within Access Database forms but my head is hurting from trying to understand how to do this for ArcPad.

Any help will be greatly received.

Charles

0 Kudos
MosquitoGIS
Frequent Contributor

A few quick questions:

I'm guessing you are collecting using a point, correct?

And what field types are you using and how are you storing the data?  (For example: Using short integers so input data is stored as a number like High as 3, Medium as 2, etc. ; or using Text so input is stored as text like High = High, Medium = Medium, etc. ?  And then are you wanting the RoH field stored in the database too, or just a thing displayed on the unit themselves after the press the Calculation button?

0 Kudos
MosquitoGIS
Frequent Contributor

And when I say stored as text or a number, I am asking how you want it to show up in your database?  What shows up in your database and what shows up to the user on the unit are totally different.

0 Kudos
charlesprowse
Deactivated User

Devin

It'll need to work for both point and polygon features ideally.

The RoH value needs to be visible on the forms and stored in the database too.

Regards field types I was trying to keep it simple with short integers (hoping to assign text as the value stored) but the risk assessment that I am trying to incorporate in the form has the following representations:

Target - Property, Range 1, Range 2 etc until 5.

Size - <150, 150-250, 250-400 etc

Failure - <1/1000, 1/1000, 1/10000 etc

Depending on the combinations selected a known answer is given as RoH.

I appreciate your assistance and apologise if my reponse doesn't provide the answer you need  

0 Kudos