Printing multiple records without a data grid?

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Printing multiple records without a data grid?

Post by jalz » Tue Apr 08, 2014 9:54 am

Hi Guys,

I've got a data grid which contains multiple records. I've had to invoke the scrollbar as there are lots of records, more than the datagrid can display. This all works ok for data entry (although I havent quite got formatting(bold/italics) to work right yet...), but I now need to print all those records out complete and I don't think I should be using the data grid for this as the rows are limited (I dont want a scroll bar).

Does anyone have a useful tutorial or a sample stack I can look at to figure out how I can achieve this.

If I was working with php, I would put all my records in a variable called $records and then use a foreach loop within a table and loop through the array, display the items from the array in its own <td> tag. Each record would be wrapped in a<tr> tag. Is there a neat way of doing this in LC? Bear in mind the data in my cells seem to have different number of lines of text in one record.

Im pretty certain you would use a foreach loop in LC, but I think is the formatting part of it that I also need to get right.

Hope the above kinda makes sense. Thanks as always
Jalz

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Printing multiple records without a data grid?

Post by bangkok » Tue Apr 08, 2014 10:08 am

jalz wrote:If I was working with php, I would put all my records in a variable called $records and then use a foreach loop within a table and loop through the array, display the items from the array in its own <td> tag. Each record would be wrapped in a<tr> tag. Is there a neat way of doing this in LC? Bear in mind the data in my cells seem to have different number of lines of text in one record.
You outline the solution... yourself ! :D

Take out the content of your DG, put it into a var... and then do what you want (loop, format, print) !

You just have to remember : datagrid use TAB as column delimiter and CR as row delimiter.

so for instance :

Code: Select all

put the DgText of grp "mydatagrid" into tVar
set itemdelimiter to tab
repeat for each line tLine in tVar
answer item 1 of tLine
answer item 2 of tLine
end repeat
PS : you can ALSO process the content of the datagrid as an array with

Code: Select all

put the DGData of grp "mydatagrid" into tArray
http://lessons.runrev.com/s/3527/m/data ... -data-grid

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Printing multiple records without a data grid?

Post by jalz » Tue Apr 08, 2014 1:12 pm

Thanks Bangkok,

Cant wait to give it a go when I am at home.I presume I can surround each row with a border or an alternative background color.
I'll have to experiment, see what is 'easily' possible.

Jalz

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Printing multiple records without a data grid?

Post by jalz » Tue Apr 15, 2014 4:28 pm

It's me again, I understand the concept thanks to bangkok of how to get the data out of my dg, what I cant seem to get my head around is how to get my fields to repeat on a layout. I know I can remove all the data out of the dg and place it in a large text field, but I would like to have some borders around the fields etc.

Can someone please look at my stack and tell me how I can clone those fields and repeat them on my layout to create my invoice like report. Im guessing that I need to group the three controls and create a repeating custom control. Am I on the right lines?

Thanking all in advance.

Jalz
Attachments
repeatfields.livecode.zip
(6.37 KiB) Downloaded 190 times
repeatfields.livecode.zip
(6.37 KiB) Downloaded 171 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Printing multiple records without a data grid?

Post by jacque » Tue Apr 15, 2014 7:43 pm

You can set up the template field the way you want and then create new fields on the fly, and each will have the properties of the template. Then you'd place the text into the new field, and align it with the one above it. It's fiddly but it works. Loop through each line of your text, creating and adjusting the fields as you go. If you need help scripting that, let us know.

But is much easier to just set the hGrid of the field to true, which will place dividing lines between each paragraph, though the spacing isn't always ideal. You can change the color of the hGrid to whatever you want.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Printing multiple records without a data grid?

Post by jalz » Thu Apr 17, 2014 10:36 pm

Hi,

I have a created 3 label fields called Title1, Firstname1, Surname1. I have grouped these 3 fields and given the group name "myFields". Im trying to loop through my data and place the data into the 3 fields

I get the following error on the first set the text… execution error at line 5 (Chunk: source is not a container), char 57

Can someone tell me how I can alter values in label field using my group name "myFields" please. my code is below.

Thanks
Jalz

Code: Select all

on mouseUp
   put the DgText of grp "Datagrid 1" into tVar
   set itemdelimiter to tab
   repeat for each line tLine in tVar
      set the text of field "Title1" to item 1 of tLine of group "myFields"
      set the text of field "Firstname1" to item 2 of tLine of group "myFields"
      set the text of field "Surname1" to item 3 of tLine of group "myFields"
   end repeat
end mouseUp

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Printing multiple records without a data grid?

Post by jacque » Thu Apr 17, 2014 10:46 pm

When you use "repeat for each", the variable contains the actual value of whatever you are parsing. In this case, tLine contains the text of a line in tVar. It isn't a line reference like "line 1", it's the text of line 1. So in this case, all you need is this:

set the text of field "Title1" to item 1 of tLine
set the text of field "Firstname1" to item 2 of tLine
set the text of field "Surname1" to item 3 of tLine

This is where using the debugger is extremely handy. Set a breakpoint right before the repeat starts and step through the code. It will still error at the same place, but right before that happens you would be able to see the value of tLine in the variables at the bottom of the script editor -- and that would clear it up right away. You could do that now before you fix it, just to see how valuable the debugger is.

To set a breakpoint, click in the left-hand gray margin (next to the line numbers) at the line where you want the debugger to stop.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Printing multiple records without a data grid?

Post by jalz » Thu Apr 17, 2014 10:57 pm

Hi Jacque,
Thanks, I know the code below works as I originally started off this way before I started grouping. The thing is I have grouped the fields because I find this the most efficient way to clone the fields on my layout, replacing the group name of the cloned fields to myFields2 and inserting in another row of data in the cloned fields. Is there a way I can reference Title1 of a specific group?

Code: Select all

set the text of field "Title1" to item 1 of tLine
set the text of field "Firstname1" to item 2 of tLine
set the text of field "Surname1" to item 3 of tLine
However

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Printing multiple records without a data grid?

Post by jacque » Fri Apr 18, 2014 4:49 pm

Code: Select all

Is there a way I can reference Title1 of a specific group?
Sure:
set the text of field "Title1" of grp <whatever > to...

If you're adding text as you clone each group then you can use "last group" as the group identifier. Otherwise you'll either need to identify it by a name or number.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply