How to count the sum of numbers in a field in Livecode

381 views Asked by At

I have an Scrolling Field and it's congaing number and word separated by space.

I want to find the sum of number (eg: 5 USA &CR 5 Uk)

3

There are 3 answers

0
Shalu On BEST ANSWER
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
Devin On

Assuming the text in your scrolling field is formatted consistently as in your example:

5 USA
5 UK
4 EUR
etc.

You can do something like this:

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
Till On
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