Being extremely new to this, and on my first project to learn PB I am having a little trouble understanding the print function.
What I am currently trying to do is write a procedure to allow a user click the print button and print the schedule stored in the DB.
Currently I have a schedule that will display in the window from the DB... all columns populate the text gadgets with out error.
I added a button gadget to the code to allow a printing of the schedule once a user is in that window.
I have added the call from the button to the procedure getprint()
From what I know and have learned I need to query the DB for the information in the table I am looking at and store it (in this case schedule$)
I did this and ran debug to make sure the data was loading and it showed the data from column 0 to be correct. I'm not aware if you can do a debug for all columns in the DB table or not... I only know of the debug GetDatabaseString(#database, 0). When I ran this it did show the correct data from that column in the DB.
However I am having trouble trying to write the code to print the data that is in the DB table, which is sports game schedule. I did look at the IDE help file to try to get a better understanding of how to implement the print function into the program but have been unsuccessful so far.
I have looked at some of the examples in the help file for printing, but none of the examples offer insight on how I could apply them to my need.
Is it possible for someone to offer a push in the right direction so I can learn what needs to be done to do this?
I need to learn how to write the code to actually print what I have queried from the DB.
Any help is greatly appreciated.
73s
Printing database information.
Printing database information.
"Occasionally stumped.... But never defeated!"
Re: Printing database information.
Here's a general purpose string list printing routine which should give you some hints, it shows how to handle centring, page breaks and counts too.
A printer page is treated pretty much as an image drawing two dimension surface rather than a typewriter type line/character driven system. You draw text and graphic elements onto a surface which is sent to a printer. The surface has dimensions determined by PrinterPageHeight() and PrinterPageWidth().
Probably the best way to use it would be to use a structure of some kind containing your print values - either a single structure for one item or a structured list for multiple items.
Oh I should mention that the program that I copied this out of was only interested in landscape printing - so this routine wasn't written with portrait printing in mind - the principle in the same however just the dimensions that change. It's not fully robust either - if you give it really wide items to print - it'll mess it up!
A printer page is treated pretty much as an image drawing two dimension surface rather than a typewriter type line/character driven system. You draw text and graphic elements onto a surface which is sent to a printer. The surface has dimensions determined by PrinterPageHeight() and PrinterPageWidth().
Probably the best way to use it would be to use a structure of some kind containing your print values - either a single structure for one item or a structured list for multiple items.
Oh I should mention that the program that I copied this out of was only interested in landscape printing - so this routine wasn't written with portrait printing in mind - the principle in the same however just the dimensions that change. It's not fully robust either - if you give it really wide items to print - it'll mess it up!
Code: Select all
Procedure fStringListPrint(List astrList.S())
; Print a list.
Protected.L llngPageCount, llngPageH, llngPageW, llngCurX, llngCurY, llngObjW, llngObjH
Protected.S lstrLine
If PrintRequester()
If StartPrinting("List")
llngPageH = PrinterPageHeight()
llngPageW = PrinterPageWidth()
LoadFont(0, "Arial", 30)
LoadFont(1, "Times New Roman", 30)
llngPageCount = 1
If StartDrawing(PrinterOutput())
DrawingFont(FontID(0))
; Header.
lstrLine = "List - " + FormatDate("%dd/%mm/%yyyy - %hh:%mm", Date())
llngObjW = TextWidth(lstrLine)
llngCurX = (llngPageW/2)-(llngObjW/2)
llngCurY = 60
DrawText(llngCurX, llngCurY, lstrLine, RGB(0, 0, 0), RGB(255, 255, 255))
; Line.
llngCurY + TextHeight(lstrLine) + 5
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 20
; Page content.
DrawingFont(FontID(1))
ForEach astrList()
lstrLine = astrList()
DrawText(70, llngCurY, lstrLine, RGB(0, 0, 0), RGB(255, 255, 255))
llngCurY + TextHeight(lstrLine) + 2
; Check for end of page.
If llngCurY>llngPageH-150
DrawingFont(FontID(0))
; Line.
llngCurY = llngPageH-110
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 6
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 10
; Footer.
lstrLine = "Page " + StrU(llngPageCount)
llngObjW = TextWidth(lstrLine)
llngCurX = (llngPageW/2)-(llngObjW/2)
DrawText(llngCurX, llngCurY, lstrLine, RGB(0, 0, 0), RGB(255, 255, 255))
; Page break.
llngPageCount + 1
NewPrinterPage()
; Header.
lstrLine = "List - " + FormatDate("%dd/%mm/%yyyy - %hh:%mm", Date())
llngObjW = TextWidth(lstrLine)
llngCurX = (llngPageW/2)-(llngObjW/2)
llngCurY = 60
DrawText(llngCurX, llngCurY, lstrLine, RGB(0, 0, 0), RGB(255, 255, 255))
; Line.
llngCurY + TextHeight(lstrLine) + 5
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 20
DrawingFont(FontID(1))
EndIf
Next
; Final footer.
DrawingFont(FontID(0))
; Line.
llngCurY = llngPageH-110
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 6
Line(50, llngCurY, llngPageW-100, 5, RGB(0, 0, 0))
llngCurY + 10
; Footer text.
lstrLine = "Page " + StrU(llngPageCount)
llngObjW = TextWidth(lstrLine)
llngCurX = (llngPageW/2)-(llngObjW/2)
DrawText(llngCurX, llngCurY, lstrLine, RGB(0, 0, 0), RGB(255, 255, 255))
StopDrawing()
FreeFont(0)
FreeFont(1)
EndIf
StopPrinting()
EndIf
EndIf
EndProcedure
NewList items.s()
For intCount = 1 To 250
AddElement(items())
items()= "item " + StrU(intCount)
Next intCount
fStringListPrint(items())
Re: Printing database information.
Thank you for the push in the right direction.... I'll see what i can do with this snippet in my project.
"Occasionally stumped.... But never defeated!"
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Printing database information.
You can try this http://www.purebasic.fr/english/viewtop ... +Module%3A. It is a data report creator and printer. Create your report and then print it. The report is based on a query entered by you in the report so you can select the tables and fields you want printed. Simple listing at the moment but will print database information that you specify.
Hope it helps
CD
Hope it helps
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.