Table field

JB sundown at pacifier.com
Sun Jul 12 07:42:51 EDT 2015


That’s nice, thank you!
I am saving it.

John Balgenorth


On Jul 12, 2015, at 4:05 AM, Peter M. Brigham <pmbrig at gmail.com> wrote:

> Here's a general function for extracting a column or columns from a tab-del table, based on a handler by Mike Doub for deleting columns. IIRC there was an exchange in this list re bug checking and generally tuning it up, and the handler I saved in my library came out of that discussion.
> 
> -- Peter
> 
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
> 
> ---------------
> 
> function getColumns pData, pColNbrs, pDelim
>   -- Extract specified columns from a table in order
>   --    pData: a tab-delimited table (delim may be overridden with pDelim)
>   --    pColNbrs: A comma separated list of columns or column ranges
>   --       to be returned in the order indicated, for example "2,7,5"
>   --       or an ascending column range: "3-5"
>   --       or a descending column range: "5-3"
>   --       or a combination "7,4-5,2,11-9"
>   -- based on deleteColumns() by Michael Doub et. al., use-LC list
> 
>   if pColNbrs = empty then return pData
>   if pDelim = empty then put tab into pDelim
>   -- first expand column ranges
>   repeat for each item pCol in pColNbrs
>      put offset("-",pCol) into dashPos
>      if dashPos = 0 then
>         put pCol & comma after tColsToReturn
>      else if dashPos = 1 then
>         -- for column numbers like -1, -2, etc.
>         put howMany(pDelim,line 1 of pData) + 1 into nbrItems
>         put pCol + 1 + nbrItems & comma after tColsToReturn
>      else
>         -- a column range
>         put char 1 to dashPos-1 of pCol into firstColNbr
>         put char dashPos+1 to -1 of pCol into lastColNbr
>         if firstColNbr < lastColNbr then
>            repeat with i = firstColNbr to lastColNbr
>               put i & comma after tColsToReturn
>            end repeat
>         else
>            repeat with i = firstColNbr down to lastColNbr
>               put i & comma after tColsToReturn
>            end repeat
>         end if  
>      end if       
>   end repeat
>   delete char -1 of tColsToReturn
>   -- then extract columns in order
>   set the columnDelimiter to pDelim
>   split pData by column
>   repeat for each item n in tColsToReturn
>      add 1 to x
>      put pData[n] into rData[x]
>   end repeat
>   combine rData by column
>   return rData
> end getColumns
> 
> 
> On Jul 11, 2015, at 7:56 PM, JB wrote:
> 
>> If you want to get all the items in a column
>> Richard Gaskin wrote a excellent function
>> specifically for that.  Like all of his code it
>> is fast.
>> 
>> John Balgenorth
>> 
>> 
>> On Jul 11, 2015, at 4:45 PM, dunbarx at aol.com wrote:
>> 
>>> The colunDelimiter will not. in and of itself, extract, say, the third item of all the lines in a tab and return formatted dataSet. DataGrids have this sort of functionality built-in, but that is still constructed from standard LC techniques.
>>> As per the above, if you wanted that third item all down the table, you have to loop through each line and dig it out, as others have already said.
>>> 
>>> 
>>> Craig Newman
>>> 
>>> 
>>> 
>>> -----Original Message-----
>>> From: Peter Haworth <pete at lcsql.com>
>>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>>> Sent: Sat, Jul 11, 2015 6:36 pm
>>> Subject: Re: Table field
>>> 
>>> 
>>> What Mike said.  It's somewhat confusing since there is a
>>> "columndelimiter"
>>> property which is set to tab by default but it seems to only
>>> be used in
>>> conjunction with the split command.
>>> 
>>> On Sat, Jul 11, 2015 at 12:57
>>> PM Mike Bonner <bonnmike at gmail.com> wrote:
>>> 
>>>> Its tab and cr delimited data,
>>> so set the itemdelimiter to tab and get item
>>>> 2 o fline 3 of field "xxx"
>>>> 
>>>> 
>>> On Sat, Jul 11, 2015 at 1:51 PM, Richmond <richmondmathewson at gmail.com>
>>>> 
>>> wrote:
>>>> 
>>>>> I have a table field containing some data I copy pasted from a
>>>> 
>>> spreadsheet
>>>>> 
>>>>> [being unable to find a reliable way to import data
>>> directly from a
>>>>> spreadsheet]
>>>>> 
>>>>> that runs across 3 columns.
>>>>> 
>>>> 
>>>> When I tried this:
>>>>> 
>>>>> put column 2 of line 3 of fld "XXX"
>>>>> 
>>>>> I
>>> had no joy.
>>>>> 
>>>>> I would be grateful if someone could tell me how to
>>> extract data from
>>>>> individual cells in a table field.
>>>>> 
>>>>> Richmond.
>>>> 
>>>> 
>>>>> _______________________________________________
>>>>> use-livecode mailing
>>> list
>>>>> use-livecode at lists.runrev.com
>>>>> Please visit this url to subscribe,
>>> unsubscribe and manage your
>>>>> subscription preferences:
>>>>> 
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>>> 
>>>> 
>>> _______________________________________________
>>>> use-livecode mailing list
>>>> 
>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe
>>> and manage your
>>>> subscription preferences:
>>>> 
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>> 
>>> _______________________________________________
>>> use-livecode
>>> mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe,
>>> unsubscribe and manage your subscription
>>> preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 





More information about the use-livecode mailing list