VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Print MSHFlexGrid

by Irene V. Yuzbasheva (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

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.

Inputs
you must supply MSHFlex Grid e.g. X = PrintMSHGrid(MSHFlexGrid1)
Assumes
The function is currently limited to 50 columns, but it can be increased.
Code Returns
the function does not return anything

Rate Print MSHFlexGrid

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
    Else
      Printer.NewPage
      Printer.Print Header; Printer.Page
      Printer.Print Titles
      Printer.Print MyText
      LLCount = 0
    End If
  Next MyRows
  Printer.EndDoc
  Screen.MousePointer = vbNormal
End Function

Download this snippet    Add to My Saved Code

Print MSHFlexGrid Comments

No comments have been posted about Print MSHFlexGrid. Why not be the first to post a comment about Print MSHFlexGrid.

Post your comment

Subject:
Message:
0/1000 characters