如何计算Livecode中字段中数字的总和
How to count the sum of numbers in a field in Livecode
我有一个滚动字段,它是由 space 分隔的连接数字和单词。
我想计算数字的总和(例如:5 USA &CR 5 Uk)
假设滚动字段中的文本格式与您的示例一致:
5 USA
5 UK
4 EUR
etc.
你可以这样做:
put fld "myScrollingFld" into tList
put 0 into tTotal
repeat for each line tLineContents in tList
put word 1 of tList into tNum
if tNum is a number then add tNum to tTotal
end if
on mouseUp
if the field "CC" is not empty then//here "CC" is an Scrolling field and it's containing the content
put 0 into aa
put fld "CC" into myData
split myData by CR
put the number of lines of (the keys of myData) into myArraylength
repeat with i = 1 to myArraylength
put 0 into zo
put myData[i] into y
split y by space
put y[1] into searchStr
if y[1]is not a number then
put 0 into var1
else
put searchStr into vari
put vari &comma after ss1
end if
end repeat
answer ss1
put sum(ss1) into aa1
answer aa1
put ss1 into second1
split second1 by comma
else
answer "List is Empty"
end if
end mouseUp
on mouseUp
repeat for each word thisWord in fld "Myfield"
if thisWord is a number then add thisWord to tSum
end repeat
answer tSum
end mouseUp
我有一个滚动字段,它是由 space 分隔的连接数字和单词。
我想计算数字的总和(例如:5 USA &CR 5 Uk)
假设滚动字段中的文本格式与您的示例一致:
5 USA
5 UK
4 EUR
etc.
你可以这样做:
put fld "myScrollingFld" into tList
put 0 into tTotal
repeat for each line tLineContents in tList
put word 1 of tList into tNum
if tNum is a number then add tNum to tTotal
end if
on mouseUp
if the field "CC" is not empty then//here "CC" is an Scrolling field and it's containing the content
put 0 into aa
put fld "CC" into myData
split myData by CR
put the number of lines of (the keys of myData) into myArraylength
repeat with i = 1 to myArraylength
put 0 into zo
put myData[i] into y
split y by space
put y[1] into searchStr
if y[1]is not a number then
put 0 into var1
else
put searchStr into vari
put vari &comma after ss1
end if
end repeat
answer ss1
put sum(ss1) into aa1
answer aa1
put ss1 into second1
split second1 by comma
else
answer "List is Empty"
end if
end mouseUp
on mouseUp
repeat for each word thisWord in fld "Myfield"
if thisWord is a number then add thisWord to tSum
end repeat
answer tSum
end mouseUp