ArcPad Adding Fields together

1224
7
02-08-2012 09:20 AM
JamesOwens
Emerging Contributor
I have 2 fields:  Pole_Ft_CATV_1    and   Pole_In_CATV_1   -  I need to add these 2 together (they are feet and then inches so it would be i.e. "12'10"".   I then need to add the two fields Pole_Ft_Power_1  and  Pole_In_Power_1.  (Same situation)
I finally need to subtract the results of the CATV_1 addition from the results of the Power_1 addition and have that result be written into the field called Pole_Separation_1.

So it would be sum of (Pole_Ft_Power_1 + Pole_In_Power_1)  -  sum of ( Pole_Ft_CATV_1 + Pole_In_CATV_1)   =   Pole_Separation_1.

I am new to this so please excuse the crudeness.

Thanks
Tags (3)
0 Kudos
7 Replies
GarethWalters
Deactivated User
Hi James,

I am going to make the assumption that all of these fields are on the same page within the form. If not please let me know.

there are two things we need to do:
1. write the calculation so that it reads the correct fields and
2. use a button or have something execute the calculation.

Firstly, if all of the inputs are on one page then that makes things a little easier. If you add a button to the same page and call it btnCalculate, go to the events of the button and where it says OnClick - write: Call myCalculation(). So when you click the button it will look for the routine we are about to write. Press Ok to everything so you are interacting with the Layer Definition of the feature. Click on the scripting button to load a new script window.

Now If you have vbScript as your default language the window should have Option Explicit written at Line 1.

Under that write: sub myCalculation()

So taking your formula: (Pole_Ft_Power_1 + Pole_In_Power_1) - sum of ( Pole_Ft_CATV_1 + Pole_In_CATV_1) = Pole_Separation_1 the script could look something like this:

sub myCalculation()
'Initiate some objects to store the measurements in
dim Pole_Ft_Power_1, Pole_In_Power_1, Pole_Ft_CATV_1, Pole_In_CATV_1, Pole_Separation_1
'This long path is how you read values from a form. There are shorter methods you can write but this hopefully explains itself.
Pole_Ft_Power_1 = Application.Map.Layers("yourPoleLayer").Forms("EDITFORM").Pages("PAGE1").Controls(txtPole_Ft_Power_1).Value
Pole_In_Power_1 = Application.Map.Layers("yourPoleLayer").Forms("EDITFORM").Pages("PAGE1").Controls(txtPole_In_Power_1).Value
Pole_Ft_CATV_1 = Application.Map.Layers("yourPoleLayer").Forms("EDITFORM").Pages("PAGE1").Controls(txtPole_Ft_CATV_1).Value
Pole_In_CATV_1 = Application.Map.Layers("yourPoleLayer").Forms("EDITFORM").Pages("PAGE1").Controls(txtPole_In_CATV_1).Value

'This line now sets the calculation to another text box that is on your form.
Application.Map.Layers(yourPoleLayer).Forms("EDITFORM").Pages("PAGE1").Controls(txtPole_Separation_1).Value = (Pole_Ft_Power_1 + Pole_In_Power_1) - ( Pole_Ft_CATV_1 + Pole_In_CATV_1)
end sub


I hope this helps.
0 Kudos
JamesOwens
Emerging Contributor
Hi James,

I am going to make the assumption that all of these fields are on the same page within the form. If not please let me know.

there are two things we need to do:
1. write the calculation so that it reads the correct fields and
2. use a button or have something execute the calculation.

Firstly, if all of the inputs are on one page then that makes things a little easier. If you add a button to the same page and call it btnCalculate, go to the events of the button and where it says OnClick - write: Call myCalculation(). So when you click the button it will look for the routine we are about to write. Press Ok to everything so you are interacting with the Layer Definition of the feature. Click on the scripting button to load a new script window.

Now If you have vbScript as your default language the window should have Option Explicit written at Line 1.

Under that write: sub myCalculation()

So taking your formula: (Pole_Ft_Power_1 + Pole_In_Power_1) - sum of ( Pole_Ft_CATV_1 + Pole_In_CATV_1) = Pole_Separation_1 the script could look something like this:



I hope this helps.




Thank you!
0 Kudos
JamesOwens
Emerging Contributor
[INDENT][/INDENT]Still isnt working.  Tried changing every variable.  Frustrating....
0 Kudos
TimHopper
Frequent Contributor
Not sure but..

The control name should be between double quotes.

...Controls("txtPole_In_CATV_1").Value

Maybe this will help?
0 Kudos
JamesOwens
Emerging Contributor
Not sure but..

The control name should be between double quotes.

...Controls("txtPole_In_CATV_1").Value

Maybe this will help?


It works!  OMG!  Details are killers....  Thank you!
0 Kudos
JamesOwens
Emerging Contributor
Okay, the subtraction works but the adding is just concatenating (sp?) the values together instead of adding together.  What is the function symbol to add fields together?
0 Kudos
TimHopper
Frequent Contributor
You need to set them as integers.

Application.Map.Layers(yourPoleLayer).Forms("EDITFORM").Pages("PAGE1").Controls("txtPole_Separation_1").Value = (int(Pole_Ft_Power_1) + int(Pole_In_Power_1)) - (int(Pole_Ft_CATV_1) + int(Pole_In_CATV_1))

That should work.
0 Kudos