我有变量 el1, el2,....el16 和 c1, c2,....c16 和 Counter 想在计数循环中使用
For Counter = 1 to 16
If el1 = "x" Then
el1 = 0
c1 = 0
Else
c1 = 1
End If
Next
If 语句适用于已定义的变量。如何将“Counter”变量与循环中的“el”和“c”结合起来识别为 el1、c1、el2、c2、...el16、c16
这是脚本的最终版本。它在 Windows 7 版本的 ArcPad 中运行良好,但 If 语句在使用移动 vbscript 运行时库的移动设备上爆炸了。可变数组方法可能会更好,但我不太确定如何修补它。任何帮助将不胜感激。
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)
'MsgBox (scoreA)
'MsgBox (scoreB)
'MsgBox (calc)
'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