home *** CD-ROM | disk | FTP | other *** search
-
- Function RptCreate (rtitle$, numcols%, textcols%, nrows%, thinbars%, thickbars%, tit1$, tit2$, foot1$, foot2$)
- ' function to create a new report
- ' Graham Hobson (72506,3410) Created: 24th September, 1991
- '
- ' Parameters:
- ' rtitle$ is the caption for the report form
- ' numcols is the number of numeric columns
- ' textcols is the number of text columns
- ' nrows is the maximum number of rows for the report (may be larger than one page)
- ' thinbars number (n) says to draw a thin line on the printed report every n rows
- ' use zero if you don't want any thinbars
- ' thickbars, ditto but with a thicker line
- ' tit1 is the main title
- ' tit2 is the secondary title
- ' foot1 is the first footnote
- ' foot2 is the second footnote
-
- On Error GoTo memerror
- ncols% = numcols% + textcols%
- If ncols% < 1 Then MsgBox "Error: there must be one or more columns", 16, "RptCreate"
- ReDim RptCol(1 To ncols%) As RptCol_Type
- If numcols% > 0 Then ReDim RptNumData(1 To numcols%, 1 To nrows%) As Single
- If textcols% > 0 Then ReDim RptTextData(1 To textcols%, 1 To nrows%) As String
- ReDim RptSortTop(10) As Integer
- ReDim RptSortBottom(10) As Integer
-
- RptForm.Show
- RptForm.caption = rtitle$
- RptForm.Refresh
-
- rpt.name = rtitle$
- rpt.headerheight = 600
- rpt.defrowheight = 225
-
- rpt.thinbars = thinbars%
- rpt.thickbars = thickbars%
- If rpt.thinbars = 0 Then rpt.thinbars = 9999
- If rpt.thickbars = 0 Then rpt.thickbars = 9999
-
- RptForm.LAB_title1.caption = tit1$
- RptForm.LAB_title2.caption = tit2$
- RptForm.LAB_footnote1.caption = foot1$
- RptForm.LAB_footnote2.caption = foot2$
-
- rpt.cols = ncols%
- rpt.numcols = numcols%
- rpt.textcols = textcols%
- rpt.rows = nrows%
-
- ' work out number of rows per page
- rpt.rowsperpage = (Printer.height - 1750 - 2000 - rpt.headerheight) / (rpt.defrowheight + 15)
- rpt.pages = (rpt.rows \ rpt.rowsperpage) + 1
-
- RptForm.grid1.cols = rpt.cols
- RptForm.grid1.rows = rpt.rowsperpage + 1
-
- rpt.currentnumcol = 0
- rpt.currenttextcol = 0
- RptCreate = 0
- Exit Function
-
- memerror:
- MsgBox "Error: report too large!", 16, "RptCreate"
- RptCreate = -1
-
- End Function
-
-
- Sub RptDefineColumn (Rhnd%, colno%, ctype$, ctitle$, cwidth%, calign%, cfmt$, bar%)
- ' routine to create a new column
- ' Rhnd is a report handle (not currently used)
- ' colno is the column number (from 1 to max)
- ' ctype is the datatype: A for text and 9 for numeric
- ' ctitle is the column title
- ' cwidth is the default width in twips
- ' calign is the alignment: 0 = left, 1 = centred, 2 = right
- ' cfmt is a standard VB format string used to format each cell value
- ' bar is a flag indicating if a vertical bar should be drawn on the printed report
- ' 0 (FALSE) = no, -1 (TRUE) = yes
-
- If colno% < 1 Or colno% > rpt.cols Then MsgBox "invalid column number", 16, "RptDefineColumn"
-
- RptCol(colno%).fmt = cfmt$
- RptCol(colno%).bar = bar%
- RptCol(colno%).datatype = ctype$
- RptCol(colno%).ctitle = ctitle$
- RptCol(colno%).cwidth = cwidth%
- RptCol(colno%).calign = calign%
-
- ' set pointer to data column
- If ctype$ = "9" Then
- If rpt.currentnumcol < rpt.numcols Then
- rpt.currentnumcol = rpt.currentnumcol + 1
- RptCol(colno%).ptr = rpt.currentnumcol
- Else
- MsgBox "too many numeric columns", 16, "RptDefineColumn"
- End If
- ElseIf ctype$ = "A" Then
- If rpt.currenttextcol < rpt.textcols Then
- rpt.currenttextcol = rpt.currenttextcol + 1
- RptCol(colno%).ptr = rpt.currenttextcol
- Else
- MsgBox "too many text columns", 16, "RptDefineColumn"
- End If
- Else
- MsgBox "Invalid datatype", 16, "RptDefineColumn"
- End If
-
- If cwidth% <= 0 Then MsgBox "invalid column width", 16, "RptDefineColumn"
-
- RptForm.grid1.col = colno% - 1
- RptForm.grid1.row = 0
- RptForm.grid1.text = ctitle$
- RptForm.grid1.colwidth = cwidth%
- RptForm.grid1.rowheight = rpt.headerheight
- RptForm.grid1.colalignment = calign%
-
- ' set sort menu item
- If colno% > 1 Then Load RptForm.MSort(colno%)
- RptForm.MSort(colno%).caption = "&" + Format$(colno%) + "." + ctitle$
- End Sub
-
- Sub RptDelete (Rhnd%)
- Unload RptForm
- End Sub
-
- Sub RptNewPage (Rhnd%, page%)
- ' procedure to display specified page of a report
- ' report handle is ignored currently
- If page% > rpt.pages Or page% < 1 Then MsgBox "invalid page number", 16, "RptNewPage"
-
- Screen.MousePointer = 11
- '-----------
- ' clear grid control
- x% = RptForm.grid1.col
- y% = RptForm.grid1.row
- RptForm.grid1.Selstartrow = 1
- RptForm.grid1.SelStartcol = 0
- RptForm.grid1.Selendrow = RptForm.grid1.rows - 1
- RptForm.grid1.Selendcol = RptForm.grid1.cols - 1
- RptForm.grid1.clip = ""
- RptForm.grid1.Selstartrow = 1
- RptForm.grid1.SelStartcol = 1
- RptForm.grid1.Selendrow = 1
- RptForm.grid1.Selendcol = 1
- '-----------
-
- rpt.page = page% ' set current page number
- RptForm.caption = RTrim$(rpt.name) + " - (Page " + Format$(rpt.page) + " of " + Format$(rpt.pages) + ")"
-
- ' populate grid with data for current page
- For y% = ((page% - 1) * rpt.rowsperpage) + 1 To (page% * rpt.rowsperpage)
- If y% > rpt.rows Then Exit For
- For x% = 1 To rpt.cols
- RptForm.grid1.row = y% Mod rpt.rowsperpage
- If RptForm.grid1.row = 0 Then RptForm.grid1.row = rpt.rowsperpage
- RptForm.grid1.col = x% - 1
-
- If RptCol(x%).datatype = "9" Then
- RptForm.grid1.text = Format$(RptNumData(RptCol(x%).ptr, y%), RTrim$(RptCol(x%).fmt) + " ")
- Else
- RptForm.grid1.text = RptTextData(RptCol(x%).ptr, y%)
- End If
- Next
- Next
-
- RptForm.Refresh
- Screen.MousePointer = 0
- End Sub
-
- Sub RptPrint (Rhnd%)
- ' prints current report page. Report handle is currently ignored
-
- Screen.MousePointer = 11
- RptForm.TXT_status.visible = -1
- RptForm.TXT_status.text = "Printing page " + Format$(rpt.page) + " of " + Format$(rpt.pages)
-
- Printer.fontname = Printer.fonts(3) ' universe on an HP laserjet
-
- '--------------------------------------------------------
- ' get max width and height of grid by looping thru columns and rows
- '--------------------------------------------------------
- maxwidth% = 0
- maxheight% = rpt.headerheight + 15
- For y% = 1 To rpt.rowsperpage
- RptForm.grid1.row = y%
- If RptForm.grid1.text = "" Then Exit For
- maxheight% = maxheight% + rpt.defrowheight + 15
- Next
- For x% = 0 To rpt.cols - 1
- RptForm.grid1.col = x%
- maxwidth% = maxwidth% + RptForm.grid1.colwidth + 15
- Next
-
- '----------------------------
- ' date and pagenumber
- '----------------------------
- Printer.fontsize = 9
- Printer.currentx = 550
- Printer.currenty = 380
- Printer.Print Format$(Now, "dd mmmm, yyyy");
- Printer.currentx = Printer.width - Printer.TextWidth("Page " + Format$(rpt.page)) - 1300
- Printer.Print "Page " + Format$(rpt.page)
-
- '----------------------------
- ' main title
- '----------------------------
- Printer.fontbold = -1
- Printer.fontsize = 16
- Printer.currentx = ((Printer.width - Printer.TextWidth(RptForm.LAB_title1.caption)) / 2) - 400
- Printer.currenty = 620
- Printer.Print RptForm.LAB_title1.caption
-
- '----------------------------
- ' second title
- '----------------------------
- Printer.fontbold = 0
- Printer.fontsize = 12
- Printer.currentx = ((Printer.width - Printer.TextWidth(RptForm.LAB_title2.caption)) / 2) - 400
- Printer.currenty = 1100
- Printer.Print RptForm.LAB_title2.caption
-
- '----------------------------
- ' footnotes
- '----------------------------
- Printer.fontbold = 0
- Printer.fontsize = 9
- Printer.currentx = 550
- Printer.currenty = Printer.height - 1600
- Printer.Print RptForm.LAB_footnote1.caption
- Printer.currentx = 550
- Printer.currenty = Printer.height - 1200
- Printer.Print RptForm.LAB_footnote2.caption
-
- ' draw grid
- Printer.fontsize = 8.25
-
- If (Printer.width - maxwidth%) > 800 Then
- orgx% = ((Printer.width - maxwidth%) / 2) - 400 ' centred report
- Else
- orgx% = 400 ' won't fit so left justified
- End If
- orgy% = 1750
-
- '--------------------------------------------------------
- ' draw outline of report table with shadows
- '--------------------------------------------------------
- Printer.currentx = orgx%
- Printer.currenty = orgy%
- Printer.drawwidth = 3
- Printer.Line -(maxwidth% + orgx%, maxheight% + orgy%), , B
- Printer.drawwidth = 1
- Printer.Line (maxwidth% + orgx%, orgy% + 35)-(maxwidth% + orgx% + 35, orgy% + maxheight% + 35), , BF
- Printer.Line (orgx% + 35, maxheight% + orgy%)-(maxwidth% + orgx% + 35, maxheight% + orgy% + 35), , BF
-
- Printer.fontbold = -1
-
- '------------------------------------------------
- ' draw column separator lines and column headings
- '------------------------------------------------
- xpos% = orgx%
- RptForm.grid1.row = 0
- For col% = 1 To rpt.cols
- RptForm.grid1.col = col% - 1
- xpos% = xpos% + RptForm.grid1.colwidth + 15
- If RptCol(col%).bar Then
- Printer.Line (xpos%, orgy%)-(xpos%, orgy% + maxheight%)
- End If
- RptPrintColHead (RptForm.grid1.text), (RptForm.grid1.colwidth), (rpt.headerheight), xpos% - RptForm.grid1.colwidth - 15, orgy%
- Next
-
- '------------------------------------------------
- ' draw horizontal lines and data
- '------------------------------------------------
- Printer.fontbold = 0
- ypos% = orgy% + rpt.headerheight + 15
- Printer.drawwidth = 3
- Printer.Line (orgx%, ypos%)-(maxwidth% + orgx%, ypos%)
-
- For y% = 1 To rpt.rowsperpage
- RptForm.grid1.col = 0
- RptForm.grid1.row = y%
- If RptForm.grid1.text = "" Then Exit For
- ypos% = ypos% + rpt.defrowheight + 15
- If (y% Mod rpt.thickbars = 0) Then
- Printer.drawwidth = 3
- Printer.Line (orgx%, ypos%)-(maxwidth% + orgx%, ypos%)
- ElseIf (y% Mod rpt.thinbars = 0) Then
- If y% = 0 Then
- Printer.drawwidth = 3
- Else
- Printer.drawwidth = 1
- End If
- Printer.Line (orgx%, ypos%)-(maxwidth% + orgx%, ypos%)
- End If
- Printer.currenty = ypos% - rpt.defrowheight + 30
-
- '-------------------------------
- ' print data items across row
- '-------------------------------
- If y% > 0 And RptForm.grid1.text <> "" Then
- Printer.currentx = orgx% + 15
- For x% = 0 To rpt.cols - 1
- RptForm.grid1.col = x%
- startcolpos% = Printer.currentx
- RptPrintCellText (RptForm.grid1.text), startcolpos%, (RptForm.grid1.colwidth), (RptForm.grid1.colalignment)
- Printer.currentx = startcolpos% + RptForm.grid1.colwidth + 15
- Next
- End If
- Next
-
- Printer.NewPage
- RptForm.TXT_status.visible = 0
- Screen.MousePointer = 0
- End Sub
-
- Sub RptPrintAll (Rhnd%)
- ' routine to print all pages for current report
-
- For n% = 1 To rpt.pages
- RptNewPage Rhnd%, n%
- RptPrint Rhnd%
- Next
-
- Printer.EndDoc
- End Sub
-
- Sub RptPrintCellText (ctext$, cstart%, cwidth%, align%)
- ' routine to print as much text as will fit into a cell
-
- If Printer.TextWidth(ctext$) >= cwidth% Then
- For n% = 1 To Len(ctext$)
- If Printer.currentx < cstart% + cwidth% - 30 Then
- Printer.Print Mid$(ctext$, n%, 1);
- End If
- Next
- Else
- Select Case align%
- Case 0 ' left
- Printer.currentx = Printer.currentx + 15
- Case 1 ' centred
- Printer.currentx = Printer.currentx + (cwidth% - Printer.TextWidth(ctext$)) / 2
- Case 2 ' right
- Printer.currentx = Printer.currentx + cwidth% - Printer.TextWidth(ctext$)
- End Select
- Printer.Print ctext$;
- End If
-
- End Sub
-
- Sub RptPrintColHead (chead$, cwidth%, rheight%, xstart%, ystart%)
- ' this subroutine prints cell text over several lines whilst trying not to split words
-
- Printer.currentx = xstart%
- Printer.currenty = ystart% + 30
-
- Do
- ' while there is space left to display text
- ' get next word
- chead$ = LTrim$(RTrim$(chead$))
- i% = InStr(chead$, " ")
- If i% = 0 Then
- word$ = " " + chead$
- chead$ = ""
- Else
- word$ = " " + Left$(chead$, i% - 1)
- chead$ = Mid$(chead$, i% + 1)
- End If
-
- ' check if space left to write this on current line
- If Printer.currentx + Printer.TextWidth(word$) < xstart% + cwidth% Then
- Printer.Print word$;
- Else
- If Printer.currentx > xstart% Then
- Printer.currenty = Printer.currenty + Printer.TextHeight(word$)
- Printer.currentx = xstart%
- End If
- RptPrintCellText word$, xtart%, cwidth%, 0
- End If
-
- Loop Until Printer.currenty >= ystart% + rheight% Or chead$ = ""
-
- End Sub
-
- Sub RptSetText (Rhnd%, colno%, rowno%, tvalue$)
- ' assigns a text value to a cell in the report
-
- If colno% < 1 Or colno% > rpt.cols Then MsgBox "invalid column number", 16, "RptSetText"
- If rowno% < 1 Or rowno% > rpt.rows Then MsgBox "invalid row number", 16, "RptSetText"
- If RptCol(colno%).datatype <> "A" Then MsgBox "not a valid text column", 16, "RptSetText"
-
- RptTextData(RptCol(colno%).ptr, rowno%) = tvalue$
- End Sub
-
- Sub RptSetValue (Rhnd%, colno%, rowno%, value!)
- ' routine to assign a numeric value to a report cell
-
- If colno% < 1 Or colno% > rpt.cols Then MsgBox "invalid column number", 16, "RptSetValue"
- If rowno% < 1 Or rowno% > rpt.rows Then MsgBox "invalid row number", 16, "RptSetValue"
- If RptCol(colno%).datatype <> "9" Then MsgBox "not a valid numeric column", 16, "RptSetValue"
-
- RptNumData(RptCol(colno%).ptr, rowno%) = value!
- End Sub
-
- Sub RptSort (colno%)
- ' routine to sort report on any single column: text or numeric
- ' The sorting algorithm is based upon that in VBSORT.BAS so the credit
- ' must go to Nelson Ford (71355,470)
-
- If colno% < 1 Or colno% > rpt.cols Then MsgBox "invalid column number", 16, "RptSort"
-
- Screen.MousePointer = 1
- RptForm.TXT_status.visible = -1
- RptForm.TXT_status.text = "sorting by " + RptCol(colno%).ctitle
-
- col% = RptCol(colno%).ptr
- typ$ = RptCol(colno%).datatype
- ply% = 1
- RptSortBottom(1) = 1
- RptSortTop(1) = rpt.rows
-
- While ply% > 0
- If RptSortBottom(ply%) >= RptSortTop(ply%) Then
- ply% = ply% - 1
- Else
- i% = RptSortBottom(ply%) - 1
- j% = RptSortTop(ply%)
- If typ$ = "9" Then
- ptn! = RptNumData(col%, j%)
- Else
- t$ = RptTextData(col%, j%)
- End If
- While i% < j%
- i% = i% + 1
- j% = j% - 1
- If typ$ = "9" Then
- While RptNumData(col%, i%) < ptn!: i% = i% + 1: Wend
- While RptNumData(col%, j%) > ptn! And j% > i%: j% = j% - 1: Wend
- Else
- While RptTextData(col%, i%) < t$: i% = i% + 1: Wend
- While RptTextData(col%, j%) > t$ And j% > i%: j% = j% - 1: Wend
- End If
- If i% < j% Then
- RptSwap i%, j%
- End If
- Wend
- j% = RptSortTop(ply%)
- Select Case typ$
- Case "9"
- If i% <> j% And RptNumData(col%, i%) > RptNumData(col%, j%) Then
- RptSwap i%, j%
- End If
- Case Else
- If i% <> j% And RptTextData(col%, i%) > RptTextData(col%, j%) Then
- RptSwap i%, j%
- End If
- End Select
- If i% - RptSortBottom(ply%) < RptSortTop(ply%) - i% Then
- RptSortBottom(ply% + 1) = RptSortBottom(ply%)
- RptSortTop(ply% + 1) = i% - 1
- RptSortBottom(ply%) = i% + 1
- Else
- RptSortTop(ply% + 1) = RptSortTop(ply%)
- RptSortBottom(ply% + 1) = i% + 1
- RptSortTop(ply%) = i% - 1
- End If
- ply% = ply% + 1
- End If
- Wend
- Screen.MousePointer = 0
- RptForm.TXT_status.visible = 0
- End Sub
-
- Sub RptSwap (i%, j%)
- ' swaps all of the column values for two specified rows
-
- ' swap numeric columns
- For n% = 1 To rpt.numcols
- x! = RptNumData(n%, i%)
- RptNumData(n%, i%) = RptNumData(n%, j%)
- RptNumData(n%, j%) = x!
- Next
- ' swap text columns
- For n% = 1 To rpt.textcols
- t$ = RptTextData(n%, i%)
- RptTextData(n%, i%) = RptTextData(n%, j%)
- RptTextData(n%, j%) = t$
- Next
- End Sub
-
-