Put items into ListMagic

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Put items into ListMagic

Post by mediaman » Mon Jan 18, 2010 11:46 am

Hi

I have a textfield called "source_text" with several phrases/sentences in it. I would like to populate a simple ListMagic as follows:

- every sentence should be on one line in ListMagic
- remaining spaces at the beginning of line 2 to ... should be deleted

Can anyone help me – thanks a lot
mediaman

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Put items into ListMagic

Post by bn » Mon Jan 18, 2010 8:28 pm

MediaMan,
the following assumes that your sentence is always terminated by a full stop, or dot. It removes linebreaks before processing.

Code: Select all

on mouseUp
   put field "SourceText" into tData
   
   -- watch out for returns or paragraphs, it would create an empty line
   replace return with empty in tData
   
   repeat
      -- find the next "."
      put offset(".",tData) into aDot
      -- if not found offset returns 0, aPoint would be 0
      -- than we exit the repeat loop
      if aDot = 0 then exit repeat
      
      -- we found a dot
      put char 1 to aDot of tData into tTestForSpace
      
      -- remove spaces at beginning of text
      repeat while char 1 of tTestForSpace is space
         delete char 1 of tTestForSpace
      end repeat
      
      put tTestForSpace & cr after tDataOut
      
      -- we just delete the data that has been processed from tData
      delete char 1 to aDot of tData
   end repeat
   delete last char of tDataOut -- a return
   put the number of chars of tDataOut
   put tDataOut after msg
   
   -- checkif there is data to put into the field
   if tDataOut is "" or tDataOut is return then 
      answer "No Data to Fill in"
      exit mouseUp
   end if
   
   put "TEXT" & return before tDataOut -- the header
   
   -- put tDataOut into the ListMagic field
   LMPopulate tDataOut
end mouseUp
regards
Bernd

mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Re: Put items into ListMagic

Post by mediaman » Mon Jan 18, 2010 8:49 pm

Hi Bernd

This works like a charm – absolutely perfect - thanks .
Mediaman

mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Re: Put items into ListMagic

Post by mediaman » Mon Jan 18, 2010 9:02 pm

Hey Bernd

Suche definitiv jemanden, der mich bei der Entwicklung meiner kleinen Applikation unterstützt, hab noch tausend Fragen – natürlich gegen Euro ;-). Hättest Du Zeit und Lust?
Meld dich doch - leider kann ich dich nicht mit einer PM erreichen.

Danke
mm

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Put items into ListMagic

Post by bn » Mon Jan 18, 2010 9:35 pm

Hi MediaMan,
thanks for the offer. I answer in english so everyone can participate. There are some very experienced Rev developers on this list that offer professional development in RunRev.
As for the ones that speak german:
Mark Schonewille and Klaus Major come to mind
Klaus can be reached via http://www.major-k.de/
and Mark can be reached via http://economy-x-talk.com/
They both mention from time to time that they do commercial projects of varying scale.
I don't do contract work. No time, since I love to answer questions on the forum for free ... :)
So if you have specific questions go ahead, if you look for someone for an application see above.
Private messaging has been disbled because of too much spam, unfortunately.
regards
Bernd

mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Re: Put items into ListMagic

Post by mediaman » Tue Jan 19, 2010 11:15 am

Hi Bernd

I managed to get the whole thing working – your script helped a lot. Now I've got the problem that a sentence can not only be terminated by a period ("."), but also by ".»" (period/quotation marks), "?" (question mark) etc.

Thanks
MediaMan

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Put items into ListMagic

Post by bn » Tue Jan 19, 2010 12:39 pm

Hi MediaMan,
it is tricky to catch all of the possible sentence endings. Here is my shot at it. The list of possible sentence endings in my script is appendable. Quote is very tricky and probably not fully covered.
Anyways

Code: Select all

on mouseUp
   put field "SourceText" into tData
   
   -- watch out for returns or paragraphs, it would create an empty line
   replace return with empty in tData
   
   -- a item list of possible sentence endings
   put ".,!,?,»," & quote  into tSentenceEndings -- add your sentence endings here
   
   repeat
      -- find the next sentenceEnding
      -- put an impossible number for offset to find
      -- into tCompare so we can test if anything was found
      -- can not take 0 because offset 0 is not found
      put length (tData) + 1 into tCompare
      
      -- check possible endings and find the lowest occurence 
      -- = the nearest hit. Has to be greater then 0
      repeat with i = 1 to the number of items of tSentenceEndings
         put offset (item i of tSentenceEndings, tData) into aHit
         
         -- catch quotes that are not at the end of sentence
         if char aHit of tData is quote and char aHit + 1 of tData is not among the items of tSentenceEndings then next repeat
         
         if aHit < tCompare and aHit > 0    then put aHit into tCompare
      end repeat
      
      if tCompare > length (tData) then exit repeat -- no sentence ending found, see above
      
      -- test for e.g. ".»", i.e two possible sentence endings in a row
      if char tCompare +1 of tData is among the items of tSentenceEndings then add 1 to tCompare
      
      -- we found a sentence ending
      put char 1 to tCompare of tData into tTestForSpace
      
      -- remove spaces at beginning of text
      repeat while char 1 of tTestForSpace is space
         delete char 1 of tTestForSpace
      end repeat
      
      put tTestForSpace & cr after tDataOut
      
      -- we just delete the data that has been processed from tData
      delete char 1 to tCompare of tData
   end repeat
   
   delete last char of tDataOut -- a return
   
   -- checkif there is data to put into the field
   if tDataOut is "" or tDataOut is return then 
      answer "No Data to Fill in"
      exit mouseUp
   end if
   
   put "TEXT" & return before tDataOut -- the header
   
   -- put tDataOut into the ListMagic field
   LMPopulate tDataOut
end mouseUp
regards
Bernd

Post Reply