[Gambas-user] gb.report
Steven Lobbezoo
steven at ...1652...
Wed Feb 20 15:12:53 CET 2008
Sure, you find the module attached.
In the mean time I found out that it has to do with images.
As soon as I make a failure in the images (f.i. a wrong filename to
load), the report.count is set tu NULL (invalid). No other error
message.
What i'm trying to do, is to write a bit of a standard interface to have
all reports I need produced easyer.
Steven
Le mercredi 20 février 2008 à 14:01 +0100, Fabien Bodard a écrit :
> can you send me project archive with your code ?
>
> it will be more simple for me !
>
>
>
> 2008/2/20, Fabien Bodard <gambas.fr at ...626...>:
> >
> > will see about that this evening,
> >
> > but the correction will be available only in the trunk first.
> >
> >
> > Fabien
> >
> > 2008/2/19, Steven Lobbezoo <steven at ...1652...>:
> > >
> > > Hi,
> > >
> > > I'm still messing around with gb.report.
> > > I try to make a module that takes care of a lot of the internals to
> > > print a report (new page : redo header, etc.)
> > > For testing I have this in the module :
> > >
> > > ' 1 Header description
> > > PUBLIC HImg AS String ' the image (logo ?) to put in
> > > PUBLIC HImgPos AS String ' the position (left, center or right) of the
> > > image
> > > PUBLIC HImgDes AS Integer[2] ' The Height, Width of the picture
> > > PUBLIC Htxt AS String ' the general title of the report
> > > PUBLIC {HtxtF} AS NEW Font ' the font of the general title
> > > PUBLIC HtxtAlign AS String ' the alignment of the headertext
> > > PUBLIC Hsub AS String ' the sub-title of the report
> > > PUBLIC {HsubF} AS NEW Font ' the sub-title font
> > >
> > > ' 2 Footer description
> > > PUBLIC FRight AS String ' the right part of the footer
> > > PUBLIC FCenter AS String ' the middle part of the footer
> > > PUBLIC FLeft AS String ' the left part of the footer
> > >
> > > ' 3 the titles and other parms of the columns
> > > PUBLIC CTits AS String[] ' array of text = titles
> > > PUBLIC {CTitsF} AS NEW Font ' the font to use
> > > PUBLIC CTitsB AS Color ' the background color
> > > PUBLIC CAlign AS String[] ' the alignment (right, left,..) of each
> > > column
> > > PUBLIC Ctot AS Boolean[] ' the columns have totals (TRUE) or not
> > > (FALSE)
> > >
> > > ' 4 The lines in the report
> > > PUBLIC Lin AS String[] ' the array of values
> > >
> > > ' 5 general parms
> > > PUBLIC ULin AS Boolean ' use lines around fields (TRUE, False)
> > > PUBLIC Target AS String ' the report to a printer, a pdf or a previewer
> > >
> > > ' 6 and the internals
> > > PrBoxH AS ReportHBox
> > > PrBoxV AS ReportVBox
> > > PrImg AS ReportImage
> > > PrLab AS ReportLabel
> > >
> > >
> > >
> > >
> > > PUBLIC FUNCTION Init() AS Boolean
> > > Report.Clear
> > > Report.size = "A4"
> > > Report.orientation = report.Portrait
> > > Report.Padding = "1 cm"
> > > Object.Attach(Report, ME, "Report")
> > > Report.Spacing = "0.2 cm"
> > > Report.LineStyle = line.Solid
> > > Report.Tag = "Report"
> > > Report.Font.Name = "Tahoma"
> > > RETURN TRUE
> > > END
> > >
> > > PUBLIC SUB DoHdr() ' do the header
> > > DIM MyPic AS Picture
> > > DIM i AS Integer
> > >
> > >
> > > PrBoxH = NEW ReportHBox(Report)
> > > PrBoxH.Height = "3 cm"
> > > PrBoxH.Width = "16 cm"
> > > PrImg = NEW ReportImage(PrBoxH)
> > > PrImg.Path = "./revimmologo.gif"
> > > PrImg.Width = "6 cm"
> > > PrImg.Height = "3 cm"
> > > PrImg.Tag = "Image"
> > > PrLab = NEW ReportLabel(PrBoxH)
> > > PrLab.Text = "Revimmo - liste du " & Date(Now)
> > > PrLab.Alignment = Align.Right
> > > PrLab.Font = Font["16"]
> > > PrLab.Expand = TRUE
> > > PrLab.Tag = "Titre"
> > >
> > > END
> > >
> > > 'x Print or draw the report
> > > PUBLIC SUB DoIt()
> > > DIM i AS Integer
> > >
> > > INC Application.Busy
> > > draw.Begin(Printer)
> > > Report.Zoom = 1
> > > Report.Resolution = Printer.Resolution
> > > Report.layout
> > >
> > > FOR i = 1 TO Report.count
> > > Report.Draw(i)
> > > IF i < Report.count THEN Printer.NewPage
> > > NEXT
> > > draw.End
> > > DEC Application.Busy
> > >
> > > END
> > >
> > > Now, the above Report.Layout allways gives the message 'Null Object'
> > > since Report.Count is and stays Null, nomather what I write in it.!
> > > I checked, and the controles made are there, and attached to the report
> > > object.
> > >
> > > Any ideas ?
> > > Thanks,
> > > Steven
> > >
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------------------------
> > > This SF.net email is sponsored by: Microsoft
> > > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > > _______________________________________________
> > > Gambas-user mailing list
> > > Gambas-user at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> >
> >
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
-------------- next part --------------
' Gambas module file
' this is the standard printroutine, replace from volmac
' it translates the page, line and field images, takes some general parms, like font and so on
' it users the gb.report to print it (to screen or to printer)
'
' so you fill some general parms and then you can fill the header and footer descriptions
' the routine will call them internally whenever nessesary
' 1 Header description
PUBLIC HImg AS String ' the image (logo ?) to put in
PUBLIC HImgPos AS String ' the position (left, center or right) of the image
PUBLIC HImgDes AS Integer[2] ' The Height, Width of the picture
PUBLIC Htxt AS String ' the general title of the report
PUBLIC {HtxtF} AS NEW Font ' the font of the general title
PUBLIC HtxtAlign AS Integer ' the alignment of the headertext
PUBLIC Hsub AS String ' the sub-title of the report
PUBLIC {HsubF} AS NEW Font ' the sub-title font
' 2 Footer description
PUBLIC FRight AS String ' the right part of the footer
PUBLIC FCenter AS String ' the middle part of the footer
PUBLIC FLeft AS String ' the left part of the footer
' 3 the titles and other parms of the columns
PUBLIC CTits AS String[] ' array of text = titles
PUBLIC CWiths AS Integer[] ' the column widths
PUBLIC {CTitsF} AS NEW Font ' the font to use
PUBLIC CTitsB AS Integer ' the background color
PUBLIC CAlign AS Integer[] ' the alignment (right, left,..) of each column
PUBLIC Ctot AS String[] ' the columns have totals any valid sql expression or blank (Count, Total, Ave, ...)
PUBLIC CFcolor AS Integer[] ' the forground color of a column
' 4 The lines in the report
PUBLIC Lin AS String[] ' the array of values
' 5 general parms
PUBLIC ULin AS Boolean ' use lines around fields (TRUE, False)
PUBLIC Target AS String ' the report to a printer, a pdf or a previewer
' 6 and the internals
PrBoxH AS ReportHBox
PrBoxV AS ReportVBox
PrImg AS ReportImage
PrLab AS ReportLabel
PrField AS ReportField
LiPP AS Integer = 20 ' lines per page
' and now for the real work
'1 Initiate the report
PUBLIC FUNCTION Init() AS Boolean
Report.Clear
Report.size = "A4"
Report.orientation = report.Portrait
'Report.Units = Units.cm
Report.Padding = "1 cm"
Object.Attach(Report, ME, "Report")
Report.Spacing = "0.5 cm"
Report.LineStyle = line.Solid
Report.Tag = "Report"
Report.Resolution = Printer.Resolution
Report.Zoom = 1
Report.Layout
Report.Font.Name = "Tahoma"
RETURN TRUE
END
PUBLIC SUB DoHdr() ' do the first header
PrBoxH = NEW ReportHBox(Report)
PrBoxH.Height = "3 cm"
PrBoxH.Width = "16 cm"
PrImg = NEW ReportImage(PrBoxH)
PrImg.Path = HImg
PrImg.Width = "6 cm"
PrImg.Height = "3 cm"
PrLab = NEW ReportLabel(PrBoxH)
PrLab.Text = Htxt
PrLab.Alignment = HtxtAlign
PrLab.Font = HtxtF
PrLab.Expand = TRUE
'for testing only !
DoSHdr()
END
PUBLIC SUB DoLines(Res AS Result) ' we write all lines from the resultset (sequence fields = col. sequence !)
DIM Clin AS Integer ' the current line
DIM Cfld AS Integer ' the field in the line
DIM hRF AS ResultField
DIM Lef, i AS Integer
DIM tmp AS String
FOR EACH Res
PrBoxH = NEW ReportHBox(Report)
PrBoxH.Height = "0.6 cm"
PrBoxH.Width = "18 cm"
FOR EACH hRF IN Res.Fields
IF Cfld > CTits.Count - 1 THEN BREAK
PrField = NEW ReportField(PrBoxH)
tmp = hRF.Name
' i = InStr(tmp, ".")
' IF i > 0 THEN
' tmp = Mid(tmp, i + 1)
' END IF ' we removed any points in the field name
TRY tmp = Res[tmp]
IF tmp THEN PrField.Data = " " & tmp & " "
PrField.Font = CTitsF
PrField.Width = Str(CWiths[Cfld]) & " cm"
PrField.Left = Str(Lef + 1) & " cm"
PrField.LineStyle = Line.Solid
PrField.Alignment = CAlign[Cfld]
IF CFcolor THEN
IF CFcolor[Cfld] <> 0 THEN PrLab.Forecolor = CFcolor[Cfld]
END IF
Lef = Lef + CWiths[Cfld] + 1
Cfld = Cfld + 1
NEXT
Clin = Clin + 1
Cfld = 0
IF Clin > LiPP THEN
' move to a new page
DoSHdr
END IF
NEXT
END
PRIVATE SUB DoSHdr() ' do the page header
DIM i AS Integer
DIM Lef AS Integer
PrBoxH = NEW ReportHBox(Report)
PrBoxH.Height = "0.6 cm"
PrBoxH.Width = "18 cm"
PrLab = NEW ReportLabel(PrBoxH)
PrLab.Text = Hsub
PrLab.Font = HsubF
' and now the cols header :
PrBoxH = NEW ReportHBox(Report)
PrBoxH.Height = "0.6 cm"
PrBoxH.Width = "18 cm"
' we do each field as per Ctits
FOR i = 0 TO Ctits.Count - 1
PrLab = NEW ReportLabel(PrBoxH)
PrLab.Text = " " & Ctits[i] & " "
PrLab.Font = CTitsF
PrLab.Width = Str(CWiths[i]) & " cm"
PrLab.Left = Str(Lef + 1) & " cm"
PrLab.LineStyle = Line.Solid
PrLab.FillColor = Color.LightGray
PrLab.FillStyle = Fill.Solid
PrLab.Alignment = CAlign[i]
IF CFcolor THEN
IF CFcolor[i] <> 0 THEN PrLab.Forecolor = CFcolor[i]
END IF
Lef = Lef + CWiths[i] + 1
NEXT
END
'x Print or draw the report
PUBLIC SUB DoIt()
frmPreview.Run(Report)
END
More information about the User
mailing list