Select to view content in your preferred language

VBS File Help

1714
7
Jump to solution
06-22-2012 07:50 AM
CamKenny
Emerging Contributor
Hello all,

I have an axf file that contains a point feature class and two related tables.  Upon creating the axf file, it nicely "generates" the form for my project (editform, tableforms).  I now need to do some vb programming to customize the data entry as well as how the data capture will flow.

While most of the vb scripting comes naturally to me, I cannot seem to get started in the right direction by defining the variables and making sure I reference the forms properly.  I have taken a few stabs at it, but each time, I am left at the first line "Option explicit" - lol

If someone has a chunk of code that will get me started, I would be forever indebted.
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ArcPadArcPad
New Contributor
Hi Cam,

From a quick diagnosis have you got the script in the correct location? I have attached a couple of screen shots for you to compare.

Let me know how you go.

Cheers,

Gareth

View solution in original post

0 Kudos
7 Replies
GarethWalters
Deactivated User
Hi Cam,

To start with try the Quick Start Land Survey tutorial in the Customizing ArcPad help documentation. This shows the steps of where to start.

If you could give a better description of the project at hand we might be able to give you a better chunk of script.

Cheers,

Gareth
0 Kudos
CamKenny
Emerging Contributor
Hi Gareth,

I couldnt find the Quick start land tutorial - I am running ArcPAD 10.  Basically, I need help with defining the variables and getting access to the forms (referencing them properly).  Once I have established the connection, I can go from there.

I will try to be as clear as possible.

I have a feature class (points) in a gdb (axf)
There are also two feature tables. One is related to the feature class, while the other feature table is related to another feature table.

When I generate the AXF within ArcMap, it goes ahead and creates my nice little form for use in ArcPAD.

Now, when I go to open the axf in Studio, I see (have) an edit form for the feature classes and within the layer definition are two tableforms.

Basically, what I need help with is "setting-up" the vbs file to reference the controls on the editform and tableform. I know this is simple enough, but maybe I am reading too much into it.

Essentially, I want to create an Editform.onload event that will get the controls from the editform (containing only 1 page) as well as the controls from the tableforms (multiple pages) so that I can pass values back and forth between the feature class and feature tables.
0 Kudos
GarethWalters
Deactivated User
Hi Cam,

It sounds like you have some fun ahead of you.

To begin with, when the form is open you can only access the related table items when those specific pages are initiated. You will have to store the values of the edit form page and then manually go to the table form and use something like the onLoad event on that.

Option Explicit

Sub getAllControls()
    'get the Form object
    Dim objForm
    'ThisEvent access the object based on the event that was executed
    Set objForm =  ThisEvent.Object 'or you could use something like this: Map.Layers("Poles").Forms("EDITFORM")


    Dim objEditPage
     Set objEditPage = objForm.Pages("General")
    Dim objAllControls
    Set objAllControls = objEditPage.Controls


    Dim objControl
    for each objControl in objAllControls
        'Creates an application variable which can be used anywhere in ArcPad.
        Application.UserProperties(objControl.Name) = objControl.Value
        Console.print Application.UserProperties(objControl.Name)
    next
End Sub

'This would set on the tableform onload event
Sub AccessTheUserProperties()
    Dim objTableForm
    Set objTableForm = ThisEvent.Object 
    Dim objTablePage = objTableForm.Pages("Lights")
    Dim objtxtBox
    Set objTxtBox.Text = Application.UserProperties("domMaterial")
End Sub


If you are after bulk updating of records in the table forms you will need to look at using the DataSource object and supplying a SQL expression that could do so. This tends to be more advanced (purely because you are not using the forms to edit).

Let me know how you go.

Cheers,

Gareth
0 Kudos
CamKenny
Emerging Contributor
Hi Gareth,

Thanks for the help.

I might have just had a light bulb come on, but not sure!

I am working with an axf and there is a feature layer in there called Applicants_2011.  In ArcStudio, I see that the layername is still Applicants_2011, but in ArcPAD, I look at the name and it is backgroundlayers.axf:Applicants_2011

Not sure if I am referencing the right things first, but my editform is called EditForm and the Page is called Page1.

I keep getting a type mismatch 'GetAllControls'
Line 1 column 1
Source Text Unavailable
0 Kudos
ArcPadArcPad
New Contributor
Hi Cam,

From a quick diagnosis have you got the script in the correct location? I have attached a couple of screen shots for you to compare.

Let me know how you go.

Cheers,

Gareth
0 Kudos
CamKenny
Emerging Contributor
Hi Gareth,

Thats exactly what it was.  Working with an axf and ArcPAD 10, there is the main area that describes the axf etc.  But once you go into the feature layer, layers definition is where the script should go.  I was placing the script at the highest level and not in the feature layers area.

Works as expected.  Thanks for your prompt replies.
0 Kudos
CamKenny
Emerging Contributor
Sorry to revive this thread.  With respect to the above code:

Option Explicit

Sub getAllControls()
    'get the Form object
    Dim objForm
    'ThisEvent access the object based on the event that was executed
    Set objForm =  ThisEvent.Object 'or you could use something like this: Map.Layers("Poles").Forms("EDITFORM")


    Dim objEditPage
     Set objEditPage = objForm.Pages("General")
    Dim objAllControls
    Set objAllControls = objEditPage.Controls


    Dim objControl
    for each objControl in objAllControls
        'Creates an application variable which can be used anywhere in ArcPad.
        Application.UserProperties(objControl.Name) = objControl.Value
        Console.print Application.UserProperties(objControl.Name)
    next
End Sub

'This would set on the tableform onload event
Sub AccessTheUserProperties()
    Dim objTableForm
    Set objTableForm = ThisEvent.Object 
    Dim objTablePage = objTableForm.Pages("Lights")
    Dim objtxtBox
    Set objTxtBox.Text = Application.UserProperties("domMaterial")
End Sub


Lets assume that I have a txtBox ("txtAppl") that contains the intial applicant number stored in the editform for the feature class.  I also have a tableform (related table) that also contains a txtBox ("txtAppl") that is empty and want to populate based on the editform "txtAppl" control.

I believe I have set the code up correctly as Gareth had pointed out, but for some reason, when I get the Dim objtxtBox and set the variable to .Text.  The application user properties "txtAppl" throws an error.  I believe it is actually throwing the error at the objTxtBox.Text portion.

If someone could explain the flow of the script, it would be greatfully appreciative.

Here is the script I have generated based on Gareth's post:

Option Explicit

Dim pApplicantsDataForm
Dim pApplicantsDataControls
Dim pTreesTableForm
Dim pTreesDataBaseControls
Dim pFieldDataTableForm
Dim pFieldDataBasePage
Dim pFieldDataBaseControls
Dim pFieldDataSiteControls
Dim pFieldDataTreeControls

Sub InitializeDataCollection() 
 Set pApplicantsDataForm = ThisEvent.Object
 Set pApplicantsDataControls = pApplicantsDataForm.Pages("page1").Controls

 Dim objApplicantsDataControls
 for each objApplicantsDataControls in pApplicantsDataControls
  Application.UserProperties(objApplicantsDataControls.Name) = objApplicantsDataControls.Value
  Console.print Application.UserProperties(objApplicantsDataControls.Name)
 next 
End Sub

Sub InitializeFieldDataTableForm()
 Set pFieldDataTableForm = ThisEvent.Object
 Set pFieldDataBasePage = pFieldDataTableForm.Pages("page1")

 Set pFieldDataBaseControls = pFieldDataTableForm.Pages("page1").Controls

 Dim txtAppl
 Set txtAppl.Text = Application.UserProperties("txtAppl")
End Sub
0 Kudos