Page 1 of 1
How do populate table field
Posted: Tue Jun 30, 2015 11:09 am
by link76
Hello,
I want to enter the values of string str_elenco in the field table (3 columns).
Code: Select all
put str_elenco "pippo1|pippo2|pippo3| ...." into str_elenco
----------------------------
| pippo1 | pippo2 | pippo3 |
| pippo4 | pippo5 | pippo6 |
----------------------------
thanks
Re: How do populate table field
Posted: Tue Jun 30, 2015 3:19 pm
by dunbarx
Hi.
A table field uses tabs to delimit columns. So you have to format your data into:
"pippo1" & tab & "pippo2" & tab & "pippo3" & return & (etc.)
Your "delimiter" is "|". And though that is fine for parsing data, it will not be accepted by a table field or a data grid. Also, the line delimiter is return. You have it also as "|", which will not format.
Craig Newman
Re: How do populate table field
Posted: Wed Jul 01, 2015 7:36 am
by link76
dunbarx wrote:Hi.
A table field uses tabs to delimit columns. So you have to format your data into:
"pippo1" & tab & "pippo2" & tab & "pippo3" & return & (etc.)
Your "delimiter" is "|". And though that is fine for parsing data, it will not be accepted by a table field or a data grid. Also, the line delimiter is return. You have it also as "|", which will not format.
Craig Newman
Thanks!
I tried it but I get this layout in the table:
Code: Select all
----------------------------
| pippo5 | pippo4 | |
| pippo3 | pippo2 | pippo1 |
----------------------------
example:
put "pippo1|pippo2|pippo3|pippo4|pippo5" into str_elenco_attese
put empty into str_ospedali
set itemDelimiter to "|"
put 0 into i
repeat with w = 1 to the num of items of str_elenco_attese
put item w of line 1 of str_elenco_attese into ospedale[w]
if i = 3 then
put ospedale[w] & return & str_ospedali into str_ospedali
put 1 into i
else
put ospedale[w]& tab &str_ospedali into str_ospedali
add 1 to i
end if
end repeat
Re: How do populate table field
Posted: Wed Jul 01, 2015 10:34 am
by bn
Hi link76,
your code does exactly what you tell it to do, it reverses the order. Best would be to step through your code using the debugger and see what goes into the variables.
I don't know why you put everything into an array, but if you need the array it is preserved in the code I changed in your script
a version that avoids the reversing of the order of items, otherwise the same as your original script, by "putting after str_ospedali" without put the new item & delimiter & str_ospedali.
Code: Select all
on mouseUp
put "pippo1|pippo2|pippo3|pippo4|pippo5" into str_elenco_attese
put empty into str_ospedali
set itemDelimiter to "|"
put 1 into i -- changed
repeat with w = 1 to the num of items of str_elenco_attese
put item w of line 1 of str_elenco_attese into ospedale[w]
if i = 3 then
put ospedale[w] & return after str_ospedali -- changed
put 1 into i
else
put ospedale[w]& tab after str_ospedali -- changed
add 1 to i
end if
end repeat
delete last byte of str_ospedali -- trailing delimiter
-- put str_ospedali into field "fTable" -- added to test put it into a table field
end mouseUp
here is a version that is for long lists a lot faster by using "repeat for each item anItem in str_elenco_attese". If you are not familiar with "repeat for each" please look it up in the dictionary.
Code: Select all
on mouseUp
put "pippo1|pippo2|pippo3|pippo4|pippo5" into str_elenco_attese
put empty into str_ospedali
set itemDelimiter to "|"
put 1 into i -- changed
repeat for each item anItem in str_elenco_attese
put anItem into ospedale[i] -- changed, if you don't need the array block this line
if i = 3 then
put anItem & return after str_ospedali -- changed
put 1 into i
else
put anItem & tab after str_ospedali -- changed
add 1 to i
end if
end repeat
delete last byte of str_ospedali -- trailing delimiter
--put str_ospedali into field "fTable" -- added to test put it into a table field
end mouseUp
Kind regards
Bernd