Page 1 of 1
Creating a "format" for data
Posted: Sun Sep 27, 2015 11:51 pm
by sms5138
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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 2:40 am
by dunbarx
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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 3:35 pm
by sms5138
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 (6.17 KiB) Viewed 4849 times
But in actuality it's pulling from the datagrid, and would be formatted like this:

- 2.PNG (4.38 KiB) Viewed 4849 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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 3:47 pm
by Klaus
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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 4:01 pm
by sms5138
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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 10:23 pm
by sms5138
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 (5.67 KiB) Viewed 4802 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 (5.23 KiB) Viewed 4802 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 (5.65 KiB) Viewed 4802 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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 10:40 pm
by dunbarx
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
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 10:55 pm
by Klaus
Yep, the "with" was a leftover from a copy/paste action, sorry for that!
Re: Creating a "format" for data
Posted: Mon Sep 28, 2015 11:04 pm
by sms5138
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