How do populate table field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

How do populate table field

Post by link76 » Tue Jun 30, 2015 11:09 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: How do populate table field

Post by dunbarx » Tue Jun 30, 2015 3:19 pm

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

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: How do populate table field

Post by link76 » Wed Jul 01, 2015 7:36 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How do populate table field

Post by bn » Wed Jul 01, 2015 10:34 am

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

Post Reply