populating field contents into a table

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
p0ntif
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Fri Mar 15, 2013 4:41 pm

populating field contents into a table

Post by p0ntif » Wed Jul 23, 2014 12:05 pm

I have a dataset that involves both questions and answers that I want populated into a data grid with 2 columns in it: 1 for the question, and 1 for the score.

I am trying to figure out the best way to display the information in the data grid and have run into a slight snag.
Some of the questions have commas in them: i.e "How many times has sir lancelot felt emotional, depressed, or tired?"

How can i insert the text correctly and still keep the commas in the questions? When i populate it by replacing the commas with tabs, I get segments of questions all over the place. Do i need to take the comments out, or is there a way to keep the commas in the final output?

Thanks in advance for your help.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: populating field contents into a table

Post by Klaus » Wed Jul 23, 2014 12:21 pm

Hm, why are you replacing the TABs?

This will do:
...
## COMMAS will not get lost:
put fld "question1" & TAB & fld "answer1" into tData
set the dgtext of grp "your dg here" to tData
...

But maybe I misunderstand your question.

p0ntif
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Fri Mar 15, 2013 4:41 pm

Re: populating field contents into a table

Post by p0ntif » Wed Jul 23, 2014 1:22 pm

First of all, let me say thank you for your comment and suggestion! I really do appreciate it.

As far as my initial question, i should have been more clear. I was initially trying to populate a datagrid with data from a field separated by commas, line by line. The commas in the questions kept screwing up my output to the datagrid as i replaced the commas with Tabs to place into the table.

However, In playing with your method, it seems simpler. So i wrote up something different. Unfortunately, i am only able to populate one line using the following script:

Code: Select all

On openCard
   put 1 into newCount
   repeat while newCount <10 # there are only 9 questions
      put qArray[newCount]["question"] & TAB & qArray[newCount]["iscore"] into theData
      add 1 to newCount
   end repeat
   set the dgText of group "output" of stack "surveyss" to theData
   put "Total Score: " & qTab into field "total" of stack "surveyss"
end openCard
What am i doing wrong that i cannot get the rest of the questions and scores to populate?
Again, thank you very much in advance!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: populating field contents into a table

Post by Klaus » Wed Jul 23, 2014 1:28 pm

Hi p0ntif,

well, you are overwriting the data in every repeat loop, so only the last answer/question pair will appear in the datagrid! 8)
...
put qArray[newCount]["question"] & TAB & qArray[newCount]["iscore"] INTO theData
...

Do this:

Code: Select all

On openCard
   put empty into theData
   repeat with newCount = 1 to 9 # there are only 9 questions
      put qArray[newCount]["question"] & TAB & qArray[newCount]["iscore"] & CR AFTER theData
   end repeat

   ## Delete trailing CR:
   delete char -1 of theData
   set the dgText of group "output" of stack "surveyss" to theData
   put "Total Score: " & qTab into field "total" of stack "surveyss"
end openCard
Best

Klaus

p0ntif
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Fri Mar 15, 2013 4:41 pm

Re: populating field contents into a table

Post by p0ntif » Wed Jul 23, 2014 1:59 pm

Klaus, you are the best! Thanks!
:D

Post Reply