Creating a "format" for data

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
sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Creating a "format" for data

Post by sms5138 » Sun Sep 27, 2015 11:51 pm

Hi everyone,

I'm sure I'm missing something (or going about this all wrong) but wanted to see if anyone has any advice for me!

I'm trying to take information from a data grid and move it to a text field but set it to where it will put it in with a certain look to it. So taking the information in column 1 and put the information in column 2 between the items of column 1 and then put a "dividing" line...

If that was completely confusing I'll give an example.

Three people give say there favorite color John like red Sarah likes green and frank likes blue. So it would look like this:


Red
John
------
Green
Sarah
------
Blue
Frank
------

So I've been doing some reading and have yet to figure out how to do this so that the information will format itself to do this regardless of the number of lines in the datagrid.

It's very possible that I'm just not searching it out properly, but I'm at a loss as to how to do this...

thank you in advance for any assistance, or resources, you may be able to provide!

-sean

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

Re: Creating a "format" for data

Post by dunbarx » Mon Sep 28, 2015 2:40 am

Hi.

Whatever it is you want to do will be both simple and a great learning experience.

But...

What was that sentence about the "Three people..."?

I thought the source text was in a dataGrid. It would not be hard to parse out those color/person paris even from that sentence, but please clarify. If really from a dataGrid, we can bring the source text into the clear by using the "dgText". Then since the result of that will be a tab and return delimited dataSet, we can simply assemble the associated pairs, inserting returns and those dividers.

Craig Newman
Last edited by dunbarx on Mon Sep 28, 2015 4:06 pm, edited 2 times in total.

sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Re: Creating a "format" for data

Post by sms5138 » Mon Sep 28, 2015 3:35 pm

Hi Craig,

Thank you for the follow up... i just read my first post, and realized how confusing it really was.. my apologies.

I have a datagrid with two columns. what i'm trying to do is pull the information from the datagrid and place it into a text field. the closest thing i can compare it to would be a like a comment section on a website... so that you'd see the "note" and who posted it. where one column is the "note" and the second column is the user. so what it's end result would look like this:
1.PNG
1.PNG (6.17 KiB) Viewed 4842 times
But in actuality it's pulling from the datagrid, and would be formatted like this:
2.PNG
2.PNG (4.38 KiB) Viewed 4842 times
I'm not sure how to set it such that it does this for all the lines in a datagrid... i'm sure that there's something i'm missing, but have yet to find it...

I think what i'm looking for is a repeat, but i'm pretty new to using them... but i'm thinking (hoping) i'm on the right track with this one.

Code: Select all

  
/*I know this 'code' is incorrect, but i'm not quite sure how to write it*/          

set the dgText of group "theDataGrid" to theData

repeat with x = 1 to the number of lines in theData
  put /*Column 1 Line x*/ & cr & /*Column 2 Line x*/ & cr & "____" into theTest
  put line x of theTest into line x of  field "read"
end repeat

So I could be going about this all wrong, but I hope my example this time around didn't cause further confusion.

Thanks in advance for any insights or resources that may point me in the right direction to accomplish this.

-Sean

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

Re: Creating a "format" for data

Post by Klaus » Mon Sep 28, 2015 3:47 pm

Hi Sean,

your missing "link" is the fact that "the dgtext of grp XYZ" is in fact a TAB and CR delimited text list!
So you can of course do this:
...

Code: Select all

## set the dgText of group "theDataGrid" to theData
## theData is EMPTY at this point!
## You want to:
PUT the dgText of group "theDataGrid" INTO theData

## NEVER access fields in a repat loop, unless really neccessary! 
## ALWAYS collect the data first in a variable, will be manyfold faster!
put empty into theTest

set itemdel to TAB
repeat with for each line tLine in theData
  put item 1 of tLine & CR & item 2 of tLine & CR & "____" & CR AFTER theTest
end repeat

## Data collected, now fill field AT ONCE!
put theTest into fld "read"
...
Best

Klaus

sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Re: Creating a "format" for data

Post by sms5138 » Mon Sep 28, 2015 4:01 pm

Hi Klaus!

Thank you so much! I look forward to giving this a shot later today, and let you know how it goes!

I really appreciate you guys help on this!

-Sean

sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Re: Creating a "format" for data

Post by sms5138 » Mon Sep 28, 2015 10:23 pm

Hi Klaus,

I seem to be missing something, but not sure.. i've tried the code that you've provided, and it seems to run into an error.

here's what i've tried so far:

Code: Select all

on mouseUp

PUT the dgText of group "DataGrid 3" INTO theData

put empty into theTest

set itemdel to TAB
repeat with for each line tLine in theData
  put item 1 of tLine & CR & item 2 of tLine & CR & "____" & CR AFTER theTest
end repeat

put theTest into fld "read"

end mouseUp
I get the following error:
Screen Shot 2015-09-28 at 5.13.16 PM.png
Screen Shot 2015-09-28 at 5.13.16 PM.png (5.67 KiB) Viewed 4795 times
I've tried this:

Code: Select all

on mouseUp

PUT the dgText of group "DataGrid 3" INTO theData

put empty into theTest

set itemdel to TAB
repeat with x = 1 for each line tLine in theData
  put item 1 of tLine & CR & item 2 of tLine & CR & "____" & CR AFTER theTest
end repeat

put theTest into fld "read"

end mouseUp
and get this:
Screen Shot 2015-09-28 at 5.15.14 PM.png
Screen Shot 2015-09-28 at 5.15.14 PM.png (5.23 KiB) Viewed 4795 times
and lastly I tried this:

Code: Select all

on mouseUp

PUT the dgText of group "DataGrid 3" INTO theData

put empty into theTest

set itemdel to TAB
repeat with x = 1 to the number of lines tLine in theData
  put item 1 of tLine & CR & item 2 of tLine & CR & "____" & CR AFTER theTest
end repeat

put theTest into fld "read"

end mouseUp
It shows no errors until i click the button and then i get this:
Screen Shot 2015-09-28 at 5.18.03 PM.png
Screen Shot 2015-09-28 at 5.18.03 PM.png (5.65 KiB) Viewed 4795 times
I wondered if i'm on the right track or just took a huge turn in the wrong direction. I've been trying to think, and look up, other ways to write this, but to no avail...

Thanks for any help you can provide!

-Sean

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

Re: Creating a "format" for data

Post by dunbarx » Mon Sep 28, 2015 10:40 pm

Hi.

Klaus has to type very quickly in order to produce the astonishing number of help replies he submits each day.

Lose the word "with" in:
repeat with for each line tLine in theData
to make:

Code: Select all

repeat for each line tLine in theData
Craig

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

Re: Creating a "format" for data

Post by Klaus » Mon Sep 28, 2015 10:55 pm

Yep, the "with" was a leftover from a copy/paste action, sorry for that!

sms5138
Posts: 126
Joined: Mon Feb 23, 2015 11:49 pm

Re: Creating a "format" for data

Post by sms5138 » Mon Sep 28, 2015 11:04 pm

Hi Craig,

I completely understand, and appreciate, all the help you guys provide.

Made the changes you've suggested, and its working like a charm!

Thanks again!

-Sean

Post Reply