Getting value along with previous line in repeat loop

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Getting value along with previous line in repeat loop

Post by alemrantareq » Sun Jul 24, 2016 8:32 pm

hello, I've two text fields "Field1" and "Field2". Filed1 has the following data:

Code: Select all

Data1
0,02GB
---------------------
Data2
7,00GB
---------------------
Data3
0,35GB
---------------------
Data4
2,00GB
---------------------
Data5
10,00GB
---------------------
Data6
2,77GB
I want to find out those data which has more than 5,00GB value. So I've wrote a button script like this:

Code: Select all

on mouseUp
   put field "Field1" into tField
   repeat for each line tLine in line 2 to -1 of tField
      if tLine > "5,00GB" then
         put tLine & cr & "---------------------" & cr after field "Field2"
      end if
   end repeat
end mouseUp
Unfortunately, it's not giving the expected result. I want the following result in field Field2:

Code: Select all

Data2
7,00GB
---------------------
Data5
10,00GB
---------------------
I need someone's help. Thanks in advance...

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Getting value along with previous line in repeat loop

Post by jmburnod » Sun Jul 24, 2016 9:47 pm

Hi,
This script does the job.
Please, write back if you need

Code: Select all

on mouseUp
   --  put field "Field1" into tField
   put field "Field1" into tData
   put empty into field "Field2"
   put empty into tData2
   --   repeat for each line tLine in line 2 to -1 of tField
   repeat for each line tLine in tData
      if "----------" is in tLine  then next repeat
      if "Data" is in tLine then
         put tLine into tRefLine
         next repeat
      end if
      --    if tLine > "5,00GB" then
      replace "," with "." in tLine -- decimal use "." not ","
      put the value of char 1 to -3 of tLine into tSize
      if isnumber(tSize) then
         if tSize > 5.00 then
            replace "." with "," in tLine
            put tRefLine & cr & tLine & cr & "---------------------" & cr after tData2
         end if
      end if
   end repeat
   delete char -1 of tData2
    put tData2 into field "Field2"
end mouseUp
Best regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Getting value along with previous line in repeat loop

Post by dunbarx » Mon Jul 25, 2016 5:12 am

Hi.

You can always trust what Jean-Marc says.

Here is another way, more brute-force, but smaller. It does rely greatly on the consistent structure of your data. This may become untenable if that varies a great deal. In a button script, with your data in fld 1

Code: Select all

on mouseUp
   get fld 1
   replace comma with "." in it
   replace "GB" with "" in it
   repeat with y = 1 to the number of lines of it
      if line y of it is a number and line y of it > 5.0000 then
         put line y - 1 of it & return  & line y of it & "GB" & return after temp
      end if
   end repeat
   put temp into fld 2
end mouseUp

Post Reply