The best way to print a long 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
CAsba
Posts: 413
Joined: Fri Sep 30, 2022 12:11 pm

The best way to print a long table field

Post by CAsba » Tue May 21, 2024 9:40 am

Hi all,
My table field has unlimited lines of data, all to be printed. It prints 36 lines per page. I tried looking up a way to print 350 lines, over 10 pages, but didn't find anything. The first 'column' of a line is an Index number that increases by 1 for each next line. I'm thinking of finding a way to set each page of the TF to Indexes 1 - 36, 37 - 72, etc., and to print each card showing the range, in a repeat loop. This procedure could be arduous, and may not even work, so I would like to ask - (a) is there a better, more obvious way that you guys may know, and if not, (b) is my idea feasible ?

CAsba
Posts: 413
Joined: Fri Sep 30, 2022 12:11 pm

Re: The best way to print a long table field

Post by CAsba » Tue May 21, 2024 12:57 pm

SOLVED
I populated the table field (from the datagrid) iusing usingn a batch of 36 lines, print a batch, populate again, print again, etc..,
using a loop to create a batch, and a second loop, til all the batches added up to the dg number of lines.

stam
Posts: 2996
Joined: Sun Jun 04, 2006 9:39 pm

Re: The best way to print a long table field

Post by stam » Tue May 21, 2024 1:33 pm

Glad you solved this!

Not being very familiar with printing I was imagining how to do this and it struck me this would be a nice print-preview feature:
Ceate a substack, laid out as you would want to print, perhaps with a first/title page and subsequent pages being different cards and just print the card. You wouldn't need to create multiple subsequent cards, just update the table/DG showing the records to be printed (i.e. 1-36, 37-72 etc). Really you wouldn't even need to export the data to a tableField if you did this...

You could include navigation/print/cancel buttons that are hidden when printing the cards... just a thought.

moodwhirr
Posts: 1
Joined: Mon Jun 10, 2024 2:29 am

Re: The best way to print a long table field

Post by moodwhirr » Mon Jun 10, 2024 2:33 am

Great workaround! Could you share the code snippet you used for the loops?

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

Re: The best way to print a long table field

Post by dunbarx » Mon Jun 10, 2024 2:19 pm

MoodWhirr:

I do something like this. Given a field "rawData", which contains all the your data, and a field "printField", which is the actual field you want to print, in a button somewhere:

Code: Select all

on mouseUp
   put fld "rawData" into tempData
   put 20 into linesPerPrint --arbitrary, your number of lines here
   put the number of lines of tempData div linesPerPrint into numPages
   if the number of lines of fld "rawData" mod linesPerPrint <> 0 then add 1 to numPages
   
   repeat numPages
      put line 1 to linesPerPrint of tempData into fld "printField"
      --revPrintField the name of fld "printField" --commented out for testing
      delete line 1 to linesPerprint of tempData
   end repeat
end mouseUp
Depending on the way you have your setup, you could print the card itself, which might contain supporting elements. And you you do not actually need a field. There is the command "revPrintText" which can take the place of field "printField" above:

Code: Select all

...
repeat numPages
      put line 1 to linesPerPrint of tempData into textToPrint
      revPrintText textToPrint
      delete line 1 to linesPerprint of tempData
end repeat
Untested, as I am driving in my car...

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9762
Joined: Fri Feb 19, 2010 10:17 am

Re: The best way to print a long table field

Post by richmond62 » Fri Jun 14, 2024 8:22 am

Why not export the field contents to an RTF document and print that?

CAsba
Posts: 413
Joined: Fri Sep 30, 2022 12:11 pm

Re: The best way to print a long table field

Post by CAsba » Mon Jun 17, 2024 4:31 pm

moodwhirr wrote:
Mon Jun 10, 2024 2:33 am
Great workaround! Could you share the code snippet you used for the loops?
Hi,
Here's the code - don't know if it will help..good luck.

Code: Select all

put 0 into fld "stockcheck4"
   repeat until fld "totallines" is tLines
      repeat until  fld "stockcheck4"  of cd "manage products"is 33 or fld "totallines" is tLines3
         add 1 to fld "stockcheck4"
         add 1 to fld "totallines"
         put the dgHilitedIndexes of group "DataGrid 3" into tIndex
         put tIndex into fld "fcol 23"
         put the dgHilitedLines of group "datagrid 3" into theLine
         put the dgDataOfLine[theLine] of group "datagrid 3" into theDataA
         put theDataA["code"]into fld "fcode" 
         put theDataA["description"]into fld "fdescription"      
         put theDataA["stock"]into fld "fstock" 
         put theDataA["type"]into fld "ftype" 
         put theDataA["location"]into fld "flocation" 
         put theDataA["checkedqty"]into fld "fcheckedqty" 
         set the dghilitedlines of grp "datagrid 3" to (the dghilitedlines of grp "datagrid 3" -1)
         
         put cr & fld "fcol 23" & tab & fld "fcode" & tab & fld "fdescription" & tab & fld "ftype" & tab & fld "flocation" & tab & fld "fstock" & tab & fld "fcheckedqty" & tab  after fld "tablefield1" of cd "printstockcheck"
         if fld "totallines" is tLines3 and fld "stockcheck4" < 33 then
            add 1 to fld "page" of cd "printstockcheck"
            ####print cd "printstockcheck"
            answer"printing"
         end if
         if fld "stockcheck4" is 33 then
            add 1 to fld "page" of cd "printstockcheck"
            ####print cd "printstockcheck"
            answer "printing"
            put 0 into fld "stockcheck4"         
            put tLines - 33 into tLines
            set the dgHilitedLines of grp "datagrid 3" of cd "manage products" to tLines
         end if
      end repeat 
      set the dgHilitedLines of grp "datagrid 3" of cd "manage products" to tLines3
      if fld "TotalLines" is tLines3 then
         exit mouseup
      end if
      
   end repeat

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”