Select to view content in your preferred language

Making calculations in ArcPad Studio form with vbs script

2305
2
04-23-2012 01:44 PM
TomPotter
Deactivated User
I am trying to use ArcPad 10 for an upcoming river inventory.  Created a form for collecting data, but would also like to use some of this data to perform some calculations and return it to the data collector.  I think I am getting close with the VBS script, but it is not returning data yet.  May have something to do with event management on the form pages.  Any help would be appreciated......Tom

Public Sub CalcValues()
'declare variables to be used
Dim el1, el2, el3, el4, el5, el6, el7, el8, el9, el10, el11, el12, el13, el14, el15, el16, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, scoreA, scoreB, calc

'set variables to form's page's controls
Set el1 = EDITFORM.Pages.Item("page4").Controls.Item("element1")
Set el2 = EDITFORM.Pages.Item("page4").Controls.Item("element2")
Set el3 = EDITFORM.Pages.Item("page4").Controls.Item("element3")
Set el4 = EDITFORM.Pages.Item("page4").Controls.Item("element4")
Set el5 = EDITFORM.Pages.Item("page4").Controls.Item("element5")
Set el6 = EDITFORM.Pages.Item("page4").Controls.Item("element6")
Set el7 = EDITFORM.Pages.Item("page4").Controls.Item("element7")
Set el8 = EDITFORM.Pages.Item("page4").Controls.Item("element8")
Set el9 = EDITFORM.Pages.Item("page5").Controls.Item("element9")
Set el10 = EDITFORM.Pages.Item("page5").Controls.Item("element10")
Set el11 = EDITFORM.Pages.Item("page5").Controls.Item("element11")
Set el12 = EDITFORM.Pages.Item("page5").Controls.Item("element12")
Set el13 = EDITFORM.Pages.Item("page5").Controls.Item("element13")
Set el14 = EDITFORM.Pages.Item("page5").Controls.Item("element14")
Set el15 = EDITFORM.Pages.Item("page5").Controls.Item("element15")
Set el16 = EDITFORM.Pages.Item("page5").Controls.Item("element16")

For Counter = 1 To 16

If el(Counter.value) = Null Then
  c(Counter.value) = 0
Else
  c(Counter.value) = 1
End If

Next
 
'do math
scoreA.Value = el1.Value + el2.Value + el3.Value + el4.Value + el5.Value + el6.Value + el7.Value + el8.Value + e9.Value + el10.Value + el11.Value + el12.Value + el13.Value + el14.Value + el15.Value + el16.Value
scoreB.Value = c1.Value + c2.Value + c3.Value + c4.Value + c5.Value + c6.Value + c7.Value + c8.Value + c9.Value + c10.Value + c11.Value + c12.Value + c13.Value + c14.Value + c15.Value + c16.Value
calc.Value = CDbl(scoreA.Value) / CDbl(scoreB.Value)
'vbscript assumes these are strings and appends them, to get the sum like you want cast them to a double (CDbl) or integer (CInt)

Set scoreA = EDITFORM.Pages.Item("Results").Controls.Item("scoreA")
Set scoreB = EDITFORM.Pages.Item("Results").Controls.Item("scoreB")
Set calc = EDITFORM.Pages.Item("Results").Controls.Item("calc")

End Sub
Tags (3)
0 Kudos
2 Replies
TomPotter
Deactivated User
Just wanted to update this post.  Finally got it working.  This is the completed script

Sub findelement
Dim el1, el2, el3, el4, el5, el6, el7, el8, el9, el10, el11, el12, el13, el14, el15, el16, scoreA, scoreB, calc

el1 = EDITFORM.Pages.Item("page4").Controls.Item("element1")
el2 = EDITFORM.Pages.Item("page4").Controls.Item("element2")
el3 = EDITFORM.Pages.Item("page4").Controls.Item("element3")
el4 = EDITFORM.Pages.Item("page4").Controls.Item("element4")
el5 = EDITFORM.Pages.Item("page4").Controls.Item("element5")
el6 = EDITFORM.Pages.Item("page4").Controls.Item("element6")
el7 = EDITFORM.Pages.Item("page4").Controls.Item("element7")
el8 = EDITFORM.Pages.Item("page4").Controls.Item("element8")
el9 = EDITFORM.Pages.Item("page5").Controls.Item("element9")
el10 = EDITFORM.Pages.Item("page5").Controls.Item("element10")
el11 = EDITFORM.Pages.Item("page5").Controls.Item("element11")
el12 = EDITFORM.Pages.Item("page5").Controls.Item("element12")
el13 = EDITFORM.Pages.Item("page5").Controls.Item("element13")
el14 = EDITFORM.Pages.Item("page5").Controls.Item("element14")
el15 = EDITFORM.Pages.Item("page5").Controls.Item("element15")
el16 = EDITFORM.Pages.Item("page5").Controls.Item("element16")

Dim c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, Counter

For Counter = 1 to 16

If "x" = Eval("el" & Counter) Then
  execute "el" & Counter & " = 0"
  execute "c" & Counter & " = 0"
Else
  execute "c" & Counter & " = 1"
End If
Next

'do math
scoreA = CInt(el1) + CInt(el2) + CInt(el3) + CInt(el4) + CInt(el5) + CInt(el6) + CInt(el7) + CInt(el8) + CInt(e9) + CInt(el10) + CInt(el11) + CInt(el12) + CInt(el13) + CInt(el14) + CInt(el15) + CInt(el16)
scoreB = CInt(c1) + CInt(c2) + CInt(c3) + CInt(c4) + CInt(c5) + CInt(c6) + CInt(c7) + CInt(c8) + CInt(c9) + CInt(c10) + CInt(c11) + CInt(c12) + CInt(c13) + CInt(c14) + CInt(c15) + CInt(c16)
calc = CDbl(scoreA) / CDbl(scoreB)
'vbscript assumes these are strings and appends them, to get the sum like you want cast them to a double (CDbl) or integer (CInt)

'Return calculated data to form......
        EDITFORM.Pages("Results").Controls("sumEl").Value = (scoreA)
EDITFORM.Pages("Results").Controls("scoreB").Value = (scoreB)
EDITFORM.Pages("Results").Controls("calc").Value = (calc)

End Sub
0 Kudos
TomPotter
Deactivated User
Oops, jumped the gun.  Works fine on the PC, but the script is blowing up at the If statement on the GPS unit running windows mobile 6.1
0 Kudos