• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert any list to a table?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert any list to a table?


  • Subject: Re: Convert any list to a table?
  • From: David Simerly <email@hidden>
  • Date: Wed, 19 Sep 2001 11:46:03 -0700
  • Url: http://www.digital-native.com

on 9/18/01 10:03 PM, Jason Bourque at <email@hidden> wrote:

> --So how do you create a false table with tabs from a list and
> --not have an extra character at the end. Plus handle even and odd lists?
> --And handle any number of columns.

Jason,

Here's yet another way to build tables that uses AppleScript's text item
delimiters, the round addition, and a try/error block to do most of the work
for you. Watch out for e-mail line breaks below. HTH.

------ begin example code

set a_list to {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh"}

makeTable(a_list, 4)

set a_list to {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh"}

makeTable(a_list, 4)

on makeTable(the_list, no_cols)
-- check the input...
if class of the_list is list and no_cols > 0 then
-- set up the vars, watch for e-mail linebreaks!
-- note the use of "round X rounding up" to determine the number of
rows...
set {tot_rows, col_count, old_delim, AppleScript's text item
delimiters, the_table} to {round ((count items in the_list) / no_cols)
rounding up, 1, AppleScript's text item delimiters, tab, ""}

-- repeat for the number of rows...
repeat tot_rows times
try
-- begin filling the table, using AS text item delims to
insert tabs...
set the_table to (the_table & (items col_count thru
((col_count + no_cols) - 1) of the_list) as text) & return
set col_count to col_count + no_cols
on error
-- if the last row is not an even number of items, the try
above will throw an error
-- and this section catches it.
set the_table to (the_table & (items col_count thru -1 of
the_list) as text) & return
end try
end repeat

-- reset the AS delims for scripts which may follow...
set AppleScript's text item delimiters to old_delim
-- return the table...
return the_table
else
-- didn't pass in a list and/or valid # of rows, so return error...
return "Error: makeList requires a list object and an integer
greater than zero."
end if
end makeTable

------ end example code

DS
______________________________________
Digital Native

Your guide through the virtual jungle.
______________________________________

Ever Wonder: Why is lemon juice made with artificial flavor, and dishwashing
liquid made with real lemons?


  • Prev by Date: Apple Remote Access
  • Next by Date: Having trouble with a QuickTime script
  • Previous by thread: Re: Convert any list to a table?
  • Next by thread: RE: Convert any list to a table?
  • Index(es):
    • Date
    • Thread