copying sentences script help

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
bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

copying sentences script help

Post by bidgeeman » Sat Mar 03, 2007 2:05 am

Hi,
Is it possible to put all sentences from single text field into individual text fields, ie, one sentence per field? can someone please give me an example?

Many thanks
Bidge

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: copying sentences script help

Post by marielle » Sat Mar 03, 2007 6:52 pm

Hi Bidge,

Please don't hesitate to rephrase your question if this doesn't answer your question.

As I understand it, your situation is one where I have a big text, stored in a field called "fulltext". Then, you have smaller text fields, for instance named "sentence1", "sentence2", "sentence3", etc. And you would like your big text to be transfered into these smaller text fields, one sentence at a time. I assume that by sentence you mean something ending with a return carriage.

Code: Select all

on mouseup
  pullSentencesFromText
end mouseup

on pullSentencesFromText
  ----------
  -- removing all fields created on the previous round
  deleteAllSentenceFields
  ----------
  put the text of field "fulltext" into tText
  ----------
  -- counting the number of sentences in the text
  set the itemdel to cr -- return carriage
  put the number of items in tText into tSentenceQty
  ----------
  -- initialising a few variables
  put 200 into tLeft; put 50 into tTop
  put 1 into tSentenceNb
  ----------
  -- creating text fields, one for each sentence
  lock screen
  repeat with tS = 1 to tSentenceQty
    put item tS of tText into tSentence
    if length(tSentence) < 3 then next repeat
    create field "sentence" && tSentenceNb
    put the long id of the last field into tFieldRef
    set the text of tFieldRef to tSentence
    set the top of tFieldRef to tTop
    ----------
    add 40 to tTop
    add 1 to tSentenceNb
  end repeat
  unlock screen
end pullSentencesFromText


on deleteAllSentenceFields
  repeat with x = the number of controls on this card down to 1
    if char 1 to 8 of the short name of control x of this card is "sentence" then delete control x of this card
  end repeat
end deleteAllSentenceFields
To set up a default format for all fields that will come to be created, use the "templateField" construct (check out the doc for more information)

Best,
Marielle

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sat Mar 03, 2007 11:40 pm

Hi Marielle,
Thank you for your help.
I created the appropriate text fields and tried ruuning the script but for some reason the "sentence" text fields all jump up into the fulltext field.

Bidge

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Sun Mar 04, 2007 12:25 am

bidgeeman wrote:I created the appropriate text fields and tried ruuning the script but for some reason the "sentence" text fields all jump up into the fulltext field.
You need to change the value for tLeft and tTop to something that works for you, then add set the left of tFieldRef to tLeft.

Note that you don't need to create the text field beforehand, they get created within the script.

Post Reply