Re: Convert any list to a table?
Re: Convert any list to a table?
- Subject: Re: Convert any list to a table?
- From: email@hidden
- Date: Wed, 19 Sep 2001 12:08:27 EDT
The problem lies here
set rowsNeeded to (anyListCount div columnsNeeded) + (anyListCount mod
columnsNeeded)
You may want to use this code instead
if (anyListCount mod columnsNeeded) is equal to 0 then
set rowsNeeded to (anyListCount div columnsNeeded)
else
set rowsNeeded to (anyListCount div columnsNeeded) + 1
end if
Understanding WHY is left as an exercise for the reader.
Jeff Baumann
email@hidden
www.linkedresources.com
In a message dated 9/19/01 12:16:49 AM, Jason Bourque wrote:
>
Ok, before I pull out any hair.
>
>
--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.
>
>
--Below is my code that works for a 2 column table.
>
>
--Thanks
>
>
--Jason Bourque
>
>
>
on createFalseTable(anyList, columnsNeeded)
>
>
set anyListCount to count of anyList
>
>
set rowsNeeded to (anyListCount div columnsNeeded) + (anyListCount mod
>
columnsNeeded)
>
>
set newList to {}
>
repeat with rowsNth from 1 to rowsNeeded
>
>
repeat with columnNth from 1 to columnsNeeded
>
try
>
item ((columnNth * rowsNeeded) - rowsNeeded + rowsNth) of
>
anyList
>
set end of newList to result
>
>
if columnNth is columnsNeeded then
>
set end of newList to return
>
else
>
set end of newList to tab
>
end if
>
end try
>
end repeat
>
end repeat
>
>
items 1 thru -2 of newList as string
>
end createFalseTable
>
>
>
set anyList to {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh"}
>
>
my createFalseTable(anyList, 2)
>
(*
>
returns
>
"aaa eee
>
bbb fff
>
ccc ggg
>
ddd hhh"
>
*)
>
my createFalseTable(anyList, 3)
>
>
(*
>
returns
>
"aaa eee bbb fff ccc ggg ddd hhh"
>
>
but should return
>
returns
>
"aaa ddd ggg
>
bbb eee hhh
>
ccc fff"
>
*)