2015-06-09 33 views
1

我有一個滾動字段,它的congaing數字和空格分隔的單詞。如何統計在Livecode字段中的數字總和

我想找到數目的總和(如:5美國& CR 5 UK)

+0

您將得到一個關於這類問題的答案,閱讀文檔或關於LiveCode的一本書(.e.g我的書爲真正的初學者編寫LiveCode)。 LiveCode免費的用戶手冊包含PDF。 – Mark

回答

2
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 
0

假設在你的滾動字段中的文本格式一致,如您的示例:

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 
0
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