Search Tools Links Login

Print MSHFlexGrid

This function retrieves data from MSHFlex Grid and prints it directly to the printer. It determines whether the information should be printed landscape or portrait.

Original Author: Irene V. Yuzbasheva


you must supply MSHFlex Grid
e.g. X = PrintMSHGrid(MSHFlexGrid1)


The function is currently limited to 50 columns, but it can be increased.


the function does not return anything


Private Sub Command1_Click()
  X = PrintMSHGrid(MSHFlexGrid1)
End Sub
Public Function PrintMSHGrid(ByVal GridToPrint As MSHFlexGrid) As Long
'This function retrieves data from MSHFlexGrid and prints it directly to the
'printer. It uses MyArray to store the distance between columns. The max number
'of columns is 50, but it can be increased if there is a need.
'Print information from mshflexgrid
  Dim MyRows, MyCols As Integer  'for-loop counters
  Dim MyText As String      'text to be printed
  Dim Titles As String      'column titles
  Dim Header As String      'page headers
  Dim MyLines As Integer     'number of lines for portrait/landscape
  Dim LLCount As Integer     'temporary line counter
  Dim MyArray(50) As Integer
  Screen.MousePointer = vbHourglass
  Titles = ""
  LLCount = 0
  Header = " - Page: "          'setup page header
  'get column headers
  For MyCols = 0 To GridToPrint.Cols - 1
    MyArray(MyCols) = Len(GridToPrint.ColHeaderCaption(0, MyCols)) + 15
    Titles = Titles & Space(15) & GridToPrint.ColHeaderCaption(0, MyCols)
  Next MyCols
  'setup printer
  Printer.Font.Size = 8          '8pts font size
  Printer.Font.Bold = True        'titles to be bold
  Printer.Font.Name = "Courier New"    'courier new font
  'determine whether to print landscape or portrait
  If (Len(MyText) > 120) Then       'landscape
    Printer.Orientation = vbPRORLandscape
    MyLines = 60
  Else                  'portrait
    Printer.Orientation = vbPRORPortrait
    MyLines = 85
  End If
  Printer.Print Header; Printer.Page
  Printer.Print Titles
  Printer.Font.Bold = False
  'get column/row values
  For MyRows = 1 To GridToPrint.Rows - 1
    MyText = ""
    GridToPrint.Row = MyRows
    For MyCols = 0 To GridToPrint.Cols - 1
      GridToPrint.Col = MyCols
        MyText = MyText & GridToPrint.Text & Space(MyArray(MyCols) - Len(GridToPrint.Text))
    Next MyCols
    LLCount = LLCount + 1
    If LLCount <= MyLines Then
      Printer.Print MyText
      Printer.Print Header; Printer.Page
      Printer.Print Titles
      Printer.Print MyText
      LLCount = 0
    End If
  Next MyRows
  Screen.MousePointer = vbNormal
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 198 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.