home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / appshell / apppring.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  4.1 KB  |  130 lines

  1. VERSION 2.00
  2. Begin Form AppPrinting 
  3.    Caption         =   "AppName"
  4.    ClientHeight    =   1635
  5.    ClientLeft      =   3420
  6.    ClientTop       =   3465
  7.    ClientWidth     =   3615
  8.    Height          =   2040
  9.    Left            =   3360
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   1635
  13.    ScaleWidth      =   3615
  14.    Top             =   3120
  15.    Width           =   3735
  16.    Begin Timer StartPrintTimer 
  17.       Enabled         =   0   'False
  18.       Interval        =   3
  19.       Left            =   3000
  20.       Top             =   1140
  21.    End
  22.    Begin CommandButton CancelCmd 
  23.       Caption         =   "Cancel"
  24.       Height          =   375
  25.       Left            =   1080
  26.       TabIndex        =   0
  27.       Top             =   1080
  28.       Width           =   1335
  29.    End
  30.    Begin Label DocumentLbl 
  31.       Alignment       =   2  'Center
  32.       Height          =   555
  33.       Left            =   180
  34.       TabIndex        =   2
  35.       Top             =   480
  36.       Width           =   3315
  37.    End
  38.    Begin Label PrintingLbl 
  39.       Alignment       =   2  'Center
  40.       Caption         =   "Printing"
  41.       Height          =   255
  42.       Left            =   240
  43.       TabIndex        =   1
  44.       Top             =   180
  45.       Width           =   3195
  46.    End
  47. Sub CancelCmd_Click ()
  48.     App_PrintCancel = True
  49.     Beep
  50. End Sub
  51. Sub Form_Load ()
  52.   AppPrinting.Caption = APP_NAME
  53.   Remove_Items_From_SysMenu AppPrinting
  54.   Place_DialogBox_in_Form AppPrinting, AppMain
  55.   DocumentLbl.Caption = UCase$(App_FileName)
  56.   App_PrintCancel = False
  57.   Screen.MousePointer = NORMAL
  58.   StartPrintTimer.Enabled = True
  59. End Sub
  60. Sub PrintData ()
  61.   ' This routine will print a file to the DEFAULT printer.  The dialog is
  62.   ' modal but still allowing the user to CANCEL the print.  The routine
  63.   ' uses VB functions to determine page size for page breaks.  A fudge of
  64.   ' one less line is used to protect for VB errors with LaserJet III's.
  65.   Dim PrintLine    As String
  66.   Dim HeaderLine   As String
  67.   Dim PageSize     As Integer
  68.   Dim LineSpace    As Integer
  69.   Dim LinesPerPage As Integer
  70.   Dim CurrentLine  As Integer
  71.   Dim IndexStart   As Integer
  72.   Dim IndexEnd     As Integer
  73.   DocumentLbl.Caption = UCase$(App_FileName) + CRLF + "Copy" + Str$(App_PrintCopyNumber)
  74.   AppPrinting.Refresh
  75.   Screen.MousePointer = NORMAL
  76.   On Error GoTo PrintDataError
  77.   ' Determine the available space on the printer page
  78.   LineSpace = Printer.TextHeight("M")
  79.   PageSize = Printer.ScaleHeight
  80.   LinesPerPage = (PageSize / LineSpace) - 1  ' -1 is fudge
  81.   HeaderLine = "Page: "
  82.   CurrentLine = 3
  83.   AppPrinting.PrintingLbl.Caption = "Printing Page : 1"
  84.   AppPrinting.Refresh
  85.   Printer.Print HeaderLine + "1" + CRLF
  86.   IndexStart = 1
  87.   IndexEnd = InStr(IndexStart, App_Data, CRLF)
  88.   Do While IndexEnd <> 0 And DoEvents()
  89.     '
  90.     ' Allow the user to cancel the print
  91.     '
  92.     rc% = SetActiveWindow(AppPrinting.hdc)
  93.     PrintLine = Mid$(App_Data, IndexStart, IndexEnd - IndexStart)
  94.     Printer.Print PrintLine
  95.     CurrentLine = CurrentLine + 1
  96.     If CurrentLine > LinesPerPage Then
  97.       CurrentLine = 3
  98.       If App_PrintCancel = True Then
  99.         AppPrinting.PrintingLbl.Caption = "Printing has been cancelled."
  100.         AppPrinting.Refresh
  101.         pause (5)
  102.         Exit Do
  103.       Else
  104.         Printer.NewPage
  105.         AppPrinting.PrintingLbl.Caption = "Printing Page : " + Str$(Printer.Page)
  106.         AppPrinting.Refresh
  107.         Printer.Print HeaderLine + LTrim$(Str$(Printer.Page)) + CRLF
  108.       End If
  109.     End If
  110.     IndexStart = IndexEnd + 2
  111.     IndexEnd = InStr(IndexStart, App_Data, CRLF)
  112.   Loop
  113.   Printer.NewPage
  114.   Printer.EndDoc
  115. ExitPrintData:
  116.   On Error GoTo 0
  117.   Exit Sub
  118. PrintDataError:
  119.   a$ = "Cannot print;" + CRLF + CRLF + "check to ensure the printer is installed correctly and your disk has sufficient available space."
  120.   MsgBox a$, MB_ICONEXCLAMATION, APP_NAME
  121.   On Error GoTo 0
  122.   Exit Sub
  123. End Sub
  124. Sub StartPrintTimer_Timer ()
  125.   StartPrintTimer.Enabled = False
  126.   pause (3)
  127.   PrintData
  128.   Unload AppPrinting
  129. End Sub
  130.