Select to view content in your preferred language

Using VB for customizing ArcPad forms

6917
6
04-04-2016 03:26 AM
Nicole_Ueberschär
Esri Regular Contributor

I looked already through a couple of postings here but I'm still lost somehow...

I used vb and js some time ago so the structure itself is quite familiar. Still I'm not familiar how to use it in ArcPad Studio and I'm wondering if someone could shed some light on where I'm wrong...

I have two main objectives:

1) seems to be very easy: I need to concatenate the values from two fields in a form, txtfarmer_id and txtplot_id and to write the new value in txtplot_ident. This is what I constructed from other scripts so far:

Sub SumPlotIdent  
  Dim objControl, objPage, plotId, plotIdent   
    Set objControl = ThisEvent.Object 
    Set objPage = ThisEvent.Object.Parent   
      plotId = objControl.Value  
      plotIdent = objPage.Controls("txtfarmer_id").Value + plotId
      objPage.Controls("txtplot_ident").Value = plotIdent

End Sub

(There is an End Sub in the last line but its not visible)

I have set plotId and plotIdent as variables, from my understanding "txtfarmer_id" and "txtplot_ident" should be the fields identifiers used in the form. I have put this script in the onchange event for the txtplot_id field, which should be objControl, right?

I keep getting following error message and have no clue what to look for:

2) For the second challenge I already found a script which I think should do what I need: https://community.esri.com/thread/74367

only that I have radio buttons at the moment and no combo box . It's also not that complicated - I only want to hide the next set of radio buttons when for the first question the answer is Agriculture:

I changed the radio buttons to combo boxes to make it easier to check for the selection, so the first is cboMain, the second cboOther.

This is what I did so far:

Sub hideShow
'Create and define Page, and Control
Dim objPage, objControl

'If cboMain field value is Ariculture (1), do the following:
If objControl.Item("cboMain").value = 1 Then
     'disable cboOther field
     objControl.Item("cboOther").Enabled = False
     'and set value of Other_Landuse field to "N/A"
     objControl.Item("cboOther").Value = "8"
Else
     'enable cboOther field
     objControl.Item("cboOther").Enabled = True
End Sub

I am getting the same error message as for the first script SumPlotIdent.

Question beyond these issues:

At the moment I remove the layer with the form in ArcPad and add it again to test it (and to get the error message). Is there an easier way to do it?

Any leads are highly appreciated!

0 Kudos
6 Replies
RebeccaStrauch__GISP
MVP Emeritus

Hi Nicole,

sorry no real answers for you right now, but will be getting my head back into ArcPad customization later this week.  But to make it easier to read the code you put in, I put it in a "tidy" program in Notepad++ and then used the advanced editor to re-post your code. Might help to get others to look.

Edit: Nicole, I removed you code since you mentioned you didn't mean to post.

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Thanks Rebecca, this code wasn't meant to be in the posting, don't know what happened... I removed it from the initial posting...

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I removed your code from the previous post, but in a quick look I have a couple things to check. FYI, mine was written during the ArcPad 6.1-7.1.x days (but still works with minor changes in 10.x) so some of my thought processes are what worked then.  I don't use ArcPad Studio much except for the text editing capabilities.  Most of my code is written at that level.

  • if you are trying to concatenate two variable, make sure they are returning and you are working with text and not numeric.
  • I typically do not include the Subroutine itself in a form for an "onchange" or "onselchange", but instead write my choice to a Application variable, then use that in my subroutine.  For example, in a <LISTBOX>, this is my code
<LABEL name="lblSpecies" x="1" y="1" width="27" height="9" caption="Species:" tooltip="" group="true" border="false"/>
<LISTBOX name="lstSpecies" x="3" y="11" width="50" height="34" listtable="" listvaluefield="" listtextfield="" defaultvalue="&quot;Brown&quot;" onselchange="Application.UserProperties(&quot;strSpecies&quot;) = ThisEvent.Object.Text" tooltip="" group="true" tabstop="true" border="true" required="true" sort="false" field="SPECIES" backgroundcolor="Cornsilk" hscroll="false">
    <LISTITEM value="Brown" text="Brown Bear"/>
    <LISTITEM value="Black" text="Black Bear"/>
    <LISTITEM value="Moose" text="Moose"/>
    <LISTITEM value="Wolf" text="Wolf"/>
    <LISTITEM value="Muskox" text="Muskox"/>
    <LISTITEM value="Caribou" text="Caribou"/>
    <LISTITEM value="Bison" text="Bison"/>
    <LISTITEM value="Sheep" text="Sheep"/>
    <LISTITEM value="MtGoat" text="Mt Goat"/>
    <LISTITEM value="Other" text="Other"/>
</LISTBOX>

there of course is much more to that, but that might spark something for you to try.

ArcPad is still a great program for complex data collection with no true alternative yet.  I've been happy that what I wrote many years ago still works.  But I admit that anytime I need to add enhancements or change things I have to shake the rust off that part of the brain.

Also, work of caution (unrelated to your issue) - if you use any .dbf files to populate form lists, unless you have an old dBase or FoxPro around...or at least an older Excel, editing/updating them is not easy or typically compatible anymore.  I had to hard code my values (and again, I'm using 7.1.1).  Luckily they were short lists.  This is just for any others that may be seeing this thread and running into that problem.

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Thanks for looking at it, Rebecca.

I figured out in the meanwhile that I just have to remove the Sub... and End Sub to make the script to run. So the concatenate works already (can't test though if it's also written to the file but that should be enough for now).

For making the combobox invisible I wasn't that successful yet unfortunately. I have tried it first in the onchange event but nothing happened when I changed the selection. So I tried with the onselchange event. At the moment it works quite ok: the second comboBox is disabled when in the first the selection with the value=96 is selected. Funnily in between only the values not the texts for the comboBox list items were shown but now it's fine. But I can't tell what I did differently now... That's the current status:

Dim objPage, objControl
Set objControl = ThisEvent.Object
Set objPage = ThisEvent.Object.Parent      
If objPage.Controls("cboMain").Value = 96 Then
   objPage.Controls("cboOther").Enabled = False
   objPage.Controls("cboOther").Value = 8
ElseIf objPage.Controls("cboMain").Value > 96 Then
   objPage.Controls("cboOther").Enabled = True
End If
Set objControl = Nothing
Set objPage = Nothing

In fact I don't have an option anymore to convert my lists I have in excel to dbf but I helped myself by saving as csv, search+replace to make list items and then just put the whole list in the (xml) form.

I have already some other requests I am trying to solve:

My client has a TableForm (something I don't find in any help document for ArcPad). Unfortunately when I try to edit it via double click as I do with the EditForm ArcPad Studio crashes. So I helped myself with the xml view but of course this it not very handy. Has someone a hint how I can solve this?

There are two tasks about this TableForm:

1) When adding a polygon first different data is entered through the EditForm before opening a related table (this is something my client figured out how to do, I have no clue...) where the user can add data through a new form that opens. So first question: in this table only maximum four entries should be possible. I assume I can do something with a loop but I didn't find the position yet - will keep you posted on this...

2) When adding a crop the user should enter a number (2-3 digits) and then the next field should automatically change to the crop name according the before typed crop number (e.g. 01 -> Maize). I thought if I put the names in a comboBox (values=numbers, text=names), look for the entered number and put the value back as output to the comboBox it should show the names but unfortunately it shows the value. Somehow comprehensible but I would be very happy if someone could tell me if (and how) I could show the text (names) instead. This is what I have so far:

Dim objControl, objPage, cropId, cropName   
    Set objControl = ThisEvent.Object 
    Set objPage = ThisEvent.Object.Parent   
      cropId = objControl.Value  
      objPage.Controls("cboCropName").Value = cropId
  Set objControl = Nothing
  Set objPage = Nothing

Is something possible like

cropName=objPage.Controls("cboCropName").Value(cropId).Text
objPage.Controls("cboCropName").Value = cropName

?

The name should also end up in the table in the end if possible...

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Two more questions:

1) Can I write a value straight to the table instead of setting a form field to a certain value?

Following scenario:

I have a question that can be answered yes or no. If no is selected the next question can be skipped and N/A should be written to the table.

Which leads me to my second question:

2) I can set the group property of an item to true. How can this help me? I was wondering if it could be of use when having a multiple choice answer for example. Can I give the group a name to make it and it's children accessible? And possibly count the selected items for example?

Thanks for your comments!

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Let me share with you how I solved my tasks, maybe it will help one or the other person looking for similar problems:

1) to concatenate the values from two fields in a form, txtfarmer_id and txtplot_id and to write the new value in txtplot_ident:

Dim objControl, objPage, plotId, plotIdent 
    Set objControl = ThisEvent.Object
    Set objPage = ThisEvent.Object.Parent 
      plotId = objControl.Value 
      plotIdent = objPage.Controls("txtFarmer").Value + plotId
      objPage.Controls("txtPlot_ident").Value = plotIdent
    Set objControl = Nothing
  Set objPage = Nothing

I have put this on the onchange event of the second text field. Issue here is, when the first field is edited the "calculated" field does not change. But you could put (almost) the same script as onchange event in the first text field, too, to be on the safer side.

2) to hide/show a second comboBox (cboOther) depending on the selection in the first comboBox (cboMain). My script here is based on https://community.esri.com/thread/74367

Dim objPage, objControl
Set objControl = ThisEvent.Object
Set objPage = ThisEvent.Object.Parent   
objPage.Controls("cboMain").Value = 0
objPage.Controls("cboOther").Value = 0
If objPage.Controls("cboMain").Value = 99 Then
      objPage.Controls("Label2").Visible = True
  objPage.Controls("cboOther").Visible = True
ElseIf objPage.Controls("cboMain").Value < 99 Then
  objPage.Controls("cboOther").Value = 8
  objPage.Controls("Label2").Visible = False
  objPage.Controls("cboOther").Visible = False
End If
Set objControl = Nothing
Set objPage = Nothing

Only when the last option (Value=99) is selected, the second comboBox shows up, including the leading text (Label2). This script is placed in the onselchange of the first comboBox. Maybe someone can shed some light on the difference between onchange and onselchange?

Still working on some other issues...