Extract items

Jim Ault JimAultWins at yahoo.com
Fri Mar 3 04:44:21 EST 2006

On 3/3/06 12:00 AM, "Joseba Aguayo" <jaguayo at eve.es> wrote:
> ¿Exists in Revolution an order similar to the Extract Rinaldi XCMD?
> ¿Is possible to extract one or two items (item 3 to 4) of a list
> separate with tabs.
Roll your own with your own rules and reactions :-)
Here is my version I put together very quickly so you may want to improve
it.  I use my style of programming code.. old habits die hard, but it works
for me.

First, make a new main stack, create two fields, paste the code into the
stack script, then put the original list into field 1, double click on the
card anywhere to run the script.

 ------start copy here -------
on mouseDoubleUp
  put empty into fld 2
  put extractItem(fld 1, 3,4, tab) into extractResult
  if extractResult contains "error" then
    answer extractResult
    exit to top
  end if
  put extractResult into fld 2
end mouseDoubleUp

function extractItem listt, aa, bb, cc
  set the itemDel to cc -- sets the desired delim
  repeat for each line LNN in listt
    if the number of items in LNN < bb then
      put "error to few items" into ans
      exit repeat
    end if
    put item aa to bb of LNN & cr after newListt
  end repeat
  if ans contains "error" then
    put cr & LNN after ans
    return ans
    delete last char of newListt
    return newListt
  end if
end extractItem
--------- end  copy -------------------

You do not have to worry about keeping the old itemDelimeter since this
setting (1) only affects the current handler (2) uses the default until
reset in each handler that runs...
which means each time the extractItem() function is called, the itemDel is a
comma, then we set it to be whatever is passed as "cc",  and
after the  extractItem() function ends, this itemDel does not affect to the
original handler.  Thus the original handler in this example will always
have the comma as its itemDel setting.

You can confirm this by adding the following line at the end of the first
answer the number of items in fld 2 --which should be 1 if you used tabs

you may want to add an error check to see if  aa<bb, if (aa, bb) are
numbers, etc.

Hope this helps

Jim Ault
Las Vegas

More information about the Use-livecode mailing list