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