home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / print / vbbook13 / vbbinp13.frm < prev    next >
Text File  |  1995-02-26  |  31KB  |  886 lines

  1. VERSION 2.00
  2. Begin Form VBBinp 
  3.    BackColor       =   &H00FF8080&
  4.    Caption         =   "VB Book Input"
  5.    ClientHeight    =   5595
  6.    ClientLeft      =   1260
  7.    ClientTop       =   1545
  8.    ClientWidth     =   5640
  9.    Height          =   6120
  10.    Icon            =   VBBINP13.FRX:0000
  11.    Left            =   1200
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   5595
  15.    ScaleWidth      =   5640
  16.    Top             =   1080
  17.    Width           =   5760
  18.    Begin Frame Outname 
  19.       BackColor       =   &H008080FF&
  20.       Caption         =   "Output To:"
  21.       Height          =   855
  22.       Left            =   3180
  23.       TabIndex        =   11
  24.       Top             =   4560
  25.       Width           =   2235
  26.       Begin ComboBox comboutname 
  27.          BackColor       =   &H00C0C0C0&
  28.          Height          =   300
  29.          Left            =   60
  30.          TabIndex        =   8
  31.          Top             =   360
  32.          Width           =   2115
  33.       End
  34.    End
  35.    Begin DirListBox Dir1 
  36.       BackColor       =   &H00C0C0C0&
  37.       Height          =   2535
  38.       Left            =   240
  39.       TabIndex        =   6
  40.       Top             =   2880
  41.       Width           =   2895
  42.    End
  43.    Begin FileListBox File1 
  44.       BackColor       =   &H00C0C0C0&
  45.       Height          =   1980
  46.       Left            =   3720
  47.       TabIndex        =   7
  48.       Top             =   2520
  49.       Width           =   1695
  50.    End
  51.    Begin DriveListBox Drive1 
  52.       BackColor       =   &H00C0C0C0&
  53.       Height          =   315
  54.       Left            =   240
  55.       TabIndex        =   5
  56.       Top             =   2520
  57.       Width           =   2895
  58.    End
  59.    Begin CheckBox Clk6 
  60.       Caption         =   "A2 (American) Paper or A4 if off"
  61.       Height          =   255
  62.       Left            =   360
  63.       TabIndex        =   15
  64.       Top             =   2040
  65.       Value           =   1  'Checked
  66.       Width           =   3255
  67.    End
  68.    Begin ComboBox Linelength 
  69.       BackColor       =   &H00C0C0C0&
  70.       Height          =   300
  71.       Left            =   4260
  72.       TabIndex        =   13
  73.       Top             =   1740
  74.       Width           =   1035
  75.    End
  76.    Begin CheckBox clk5 
  77.       Caption         =   "Set Line Wrap On"
  78.       Height          =   255
  79.       Left            =   360
  80.       TabIndex        =   4
  81.       Top             =   1680
  82.       Value           =   1  'Checked
  83.       Width           =   3255
  84.    End
  85.    Begin TextBox Text1 
  86.       BackColor       =   &H00FF8080&
  87.       BorderStyle     =   0  'None
  88.       Enabled         =   0   'False
  89.       Height          =   195
  90.       Left            =   4260
  91.       MultiLine       =   -1  'True
  92.       TabIndex        =   14
  93.       Text            =   "Text Width:"
  94.       Top             =   1500
  95.       Width           =   1035
  96.    End
  97.    Begin CheckBox clk4 
  98.       Caption         =   "Use Speaker"
  99.       Height          =   255
  100.       Left            =   360
  101.       TabIndex        =   3
  102.       Top             =   1320
  103.       Value           =   1  'Checked
  104.       Width           =   3255
  105.    End
  106.    Begin CheckBox clk3 
  107.       Caption         =   "Print Page Numbers"
  108.       Height          =   255
  109.       Left            =   360
  110.       TabIndex        =   2
  111.       Top             =   960
  112.       Value           =   1  'Checked
  113.       Width           =   3255
  114.    End
  115.    Begin PictureBox Picture1 
  116.       BackColor       =   &H00FF8080&
  117.       Height          =   495
  118.       Left            =   4500
  119.       Picture         =   VBBINP13.FRX:0302
  120.       ScaleHeight     =   465
  121.       ScaleWidth      =   465
  122.       TabIndex        =   12
  123.       Top             =   660
  124.       Width           =   495
  125.    End
  126.    Begin CheckBox clk2 
  127.       Caption         =   "Print Date/Time on each Page"
  128.       Height          =   255
  129.       Left            =   360
  130.       TabIndex        =   1
  131.       Top             =   600
  132.       Value           =   1  'Checked
  133.       Width           =   3255
  134.    End
  135.    Begin CommandButton go 
  136.       Caption         =   "Do It"
  137.       Default         =   -1  'True
  138.       Height          =   375
  139.       Left            =   4800
  140.       TabIndex        =   9
  141.       Top             =   240
  142.       Width           =   735
  143.    End
  144.    Begin CommandButton Cancel 
  145.       Caption         =   "Cancel"
  146.       Height          =   375
  147.       Left            =   3960
  148.       TabIndex        =   10
  149.       Top             =   240
  150.       Width           =   735
  151.    End
  152.    Begin CheckBox clk1 
  153.       BackColor       =   &H00FFFFFF&
  154.       Caption         =   "Print Filename on each Page"
  155.       ForeColor       =   &H00000000&
  156.       Height          =   255
  157.       Left            =   360
  158.       TabIndex        =   0
  159.       Top             =   240
  160.       Value           =   1  'Checked
  161.       Width           =   3255
  162.    End
  163. End
  164. Dim ESC$, FF$, LF$, FileName$, outfile$, NewName$, NL$
  165. Dim Page%, num$, tune%
  166. Dim PC As Flags
  167. Dim PaperAmerican
  168. Dim PaperWidth
  169. Dim ToAFile
  170. Dim LeftSide%, RightSide%, FirstPass%
  171. Dim Bookmark%, Junk%, Abort%
  172. Dim Default$, Title$, Msg$
  173.  
  174. Dim lastchange As Integer
  175.  
  176. Const fileboxclick = 0, dirsboxclick = 1
  177. 'Const True = -1, False = 0
  178.  
  179. Sub BuildArray (ptrarray&(), pgcount%)
  180.     'Was Satic Sub ...
  181.     MaxLines% = 66                                'Maximum number of lines
  182.     Offset& = 1                                   'Start of file (seek point)
  183.     Open FileName$ For Binary Access Read As #1 Len = 1   'Open file to check
  184.     TotalSize& = LOF(1)                           'Get LEN of file so we don't read too far
  185.     FileLeft& = TotalSize&                        'Setup a counter to show whats left
  186.  
  187.     'FRE is not supported by VB.  Use GetFreeSpace() instead (see global module)
  188.     memAvail& = GetFreeSpace(0)        '65536  FRE(FileName$) - 2048  'Check available string memory
  189.     If memAvail& < 2048 Then Error 14             'Force out of memory error
  190.     SixteenK% = 16384
  191.  
  192.    If TotalSize& > SixteenK% Then                'Set a buffer size
  193.       If memAvail& > SixteenK% Then              'If the file is larger than 16K
  194.          BufAvail& = SixteenK%                   'Set it to 16k
  195.       Else
  196.          BufAvail& = memAvail&
  197.       End If
  198.    Else
  199.       If TotalSize& < memAvail& Then             'Otherwise set it to file size
  200.          BufAvail& = TotalSize&
  201.       End If
  202.       BuffSize% = BufAvail&
  203.    End If
  204.  
  205.    pgcount% = 1                                  'Initialize page count
  206.    ptrarray&(pgcount%) = 1                       'First pointer is always 1
  207.    LnCount% = 0                                  'Initialize line count
  208.  
  209. GetPage:                                         'Read the file
  210.                                                  
  211.   If FileLeft& < BufAvail& Then                  'Check amount left to read
  212.      Buffer$ = Space$(FileLeft&)                 'If less than our buffer, use lessor
  213.   Else
  214.      Buffer$ = Space$(BufAvail&)                 'Otherwise use full buffer size
  215.   End If
  216.  
  217.   Get #1, Offset&, Buffer$                       'Read in a buffers worth
  218.   stptr% = 1                                     'Pointer into buffer$
  219.   LastLine% = 0                                  'remember last position
  220.  
  221. PageCheck:
  222.   Junk% = DoEvents()                             'yield some time to the system
  223.   TempLn% = InStr(stptr%, Buffer$, LF$)          'Position of next linefeed
  224.   temppg% = InStr(stptr%, Buffer$, FF$)          'Position of next pagefeeds
  225.  
  226.   If temppg% Then                                'If there was a page feed
  227.      If temppg% < TempLn% Or TempLn% = 0 Then    '  was it before our linefeed?
  228.         pgcount% = pgcount% + 1                  '  yes then bump page count
  229.         ptrarray&(pgcount%) = Offset& + temppg%  '  set next array element
  230.         stptr% = temppg% + 1                     '  set instr pointer
  231.         LnCount% = 0                             '  reset linecount
  232.         If stptr% < Len(Buffer$) Then GoTo PageCheck 'and loop back for more
  233.       End If
  234.   End If
  235.  
  236.   If TempLn% Then                                'Linefeed
  237.     If PC.LineWrap Then                           'If Line Wrap, check length
  238.         If TempLn% - stptr% > PC.Linelen Then     'Greater than 80?
  239.             Do                                   'check for line wrap
  240.                 LnCount% = LnCount% + 1          'increment line
  241.                 If LnCount% = MaxLines% Then
  242.                     GoTo PageBreak               '> 66 lines
  243.                 End If
  244.                 stptr% = stptr% + PC.Linelen
  245.             Loop While TempLn% - stptr% > PC.Linelen
  246.         End If
  247.     End If
  248.     LnCount% = LnCount% + 1                      'Increment page count
  249.  
  250. PageBreak:
  251.      If LnCount% = MaxLines% Then
  252.         pgcount% = pgcount% + 1
  253.             If pgcount% > 512 Then
  254.                Msg$ = "Too may pages - printing only 512."
  255.                MsgBox Msg$, 0, "Notice"
  256.                GoTo EndBuild
  257.             End If
  258.         ptrarray&(pgcount%) = Offset& + TempLn%  'point to next point in file
  259.         LnCount% = 0
  260.      End If
  261.      
  262.      stptr% = TempLn% + 1                        'point ahead 1 byte for next scan
  263.      If stptr% <= Len(Buffer$) Then
  264.         GoTo PageCheck                           'keep checking
  265.      End If
  266.   End If
  267.  
  268.   Offset& = Offset& + Len(Buffer$)              'Pointer into file (tally)
  269.   stptr% = 1                                    'Reset Buffer pointer
  270.   FileLeft& = TotalSize& - Offset&              'Calculate how much is left
  271.   If Offset& < TotalSize& Then GoTo GetPage     'If more text in file, keep going
  272.  
  273. EndBuild:
  274.   ptrarray&(pgcount% + 1) = TotalSize&          'Set last pointer to end of file
  275.  
  276. Close #1                                        'Close input file
  277. End Sub                                         'End of BuildArray Sub
  278.  
  279. Sub Cancel_Click ()
  280.     'If user clicks on the cancel button then ...
  281.     Close
  282.     End
  283. End Sub
  284.  
  285. Sub clk1_Click ()
  286.       'Toggle on/off
  287.       If PC.FileTitle = 0 Then
  288.         PC.FileTitle = -1
  289.         PC.DoHeader = -1
  290.       Else
  291.         PC.FileTitle = 0
  292.         'Still have to do the Header if clk2 or clk3 buttons are checked
  293.         If (clk2.Value = -1) Or (clk3.Value = -1) Then
  294.             PC.DoHeader = -1
  295.         Else
  296.             PC.DoHeader = 0
  297.         End If
  298.       End If
  299. End Sub
  300.  
  301. Sub clk2_Click ()
  302.       'Toggle on/off
  303.       If PC.CurDate = 0 Then
  304.         PC.CurDate = -1
  305.         PC.DoHeader = -1
  306.       Else
  307.         PC.CurDate = 0
  308.         'Still have to do the Header if clk1 or clk3 buttons are checked
  309.         If (clk1.Value = -1) Or (clk3.Value = -1) Then
  310.             PC.DoHeader = -1
  311.         Else
  312.             PC.DoHeader = 0
  313.         End If
  314.       End If
  315. End Sub
  316.  
  317. Sub clk3_Click ()
  318.       'Toggle on/off
  319.       If PC.PgNumber = 0 Then
  320.         PC.PgNumber = -1
  321.         PC.DoHeader = -1
  322.       Else
  323.         PC.PgNumber = 0
  324.         'Still have to do the Header if clk1 or clk2 buttons are checked
  325.         If (clk1.Value = -1) Or (clk2.Value = -1) Then
  326.             PC.DoHeader = -1
  327.         Else
  328.             PC.DoHeader = 0
  329.         End If
  330.       End If
  331. End Sub
  332.  
  333. Sub clk4_Click ()
  334.     'Toggle on/off
  335.     tune% = Not tune%
  336. End Sub
  337.  
  338. Sub clk5_Click ()
  339.       'Toggle on/off
  340.       PC.LineWrap = Not PC.LineWrap
  341. End Sub
  342.  
  343. Sub Clk6_Click ()
  344.       If PaperAmerican = True Then    'if true, changing to A4
  345.         PaperAmerican = False
  346.         PaperWidth = 185           'A4 (British) paper width
  347.         PC.tempmrg = 100           'right side left margin of
  348.         'PC.tempmrg = 90           'right side left margin of
  349.         Do While linelength.ListCount
  350.             linelength.RemoveItem 0
  351.         Loop
  352.         linelength.AddItem "65"
  353.         linelength.AddItem "70"
  354.         linelength.AddItem "75"
  355.         linelength.AddItem "80"
  356.         linelength.AddItem "85"
  357.         linelength.AddItem "90"
  358.         linelength.Text = linelength.List(5)
  359.       Else
  360.         PaperAmerican = True       'A2 (American) paper
  361.         PaperWidth = 175
  362.         PC.tempmrg = 95            'right side left margin of 95
  363.         'linelength.text = "80"
  364.         
  365.         Do While linelength.ListCount
  366.             linelength.RemoveItem 0
  367.         Loop
  368.         linelength.AddItem "65"
  369.         linelength.AddItem "70"
  370.         linelength.AddItem "75"
  371.         linelength.AddItem "80"
  372.         linelength.Text = linelength.List(3)
  373.  
  374.       End If
  375. End Sub
  376.  
  377. Sub comboutname_Click ()
  378.     'Select where to send the output
  379.     Select Case comboutname.Text
  380.     Case "LPT1"
  381.         outfile$ = "LPT1"
  382.     Case "LPT2"
  383.         outfile$ = "LPT2"
  384.     Case "COM1"
  385.         outfile$ = "COM1"
  386.     Case "COM2"
  387.         outfile$ = "COM2"
  388.     Case "file"
  389.         If file1.FileName = "" Then
  390.             comboutname.Text = "LPT1"
  391.             outfile$ = "LPT1"
  392.             Msg$ = "You must select an input filename first!"
  393.             MsgBox Msg$, 32
  394.             file1.SetFocus                              'set focus to file list box
  395.             Exit Sub
  396.         End If
  397.  
  398.         'Now make up a default output filename with same name and PRN as extension
  399.         outfile$ = UCase$(Left$(file1.FileName, InStr(file1.FileName, ".")) + "PRN")
  400.         Msg$ = NL$ + NL$ + "            WAIT" + NL$
  401.    
  402.         Msg$ = Msg$ + "Enter filename to print to:" + NL$ + NL$
  403.         Msg$ = Msg$ + "NOTE:  Two files will be made -- one prefixed "         '+ NL$
  404.         
  405.         Msg$ = Msg$ + "with a 1 for side number one and another file "         '+ NL$
  406.         Msg$ = Msg$ + "prefixed with a 2 for side number two.  File extension MUST "
  407.         Msg$ = Msg$ + "be used!"
  408.         outfile$ = InputBox$(Msg$, "Output File Name", outfile$) 'Get a filename
  409.         If outfile$ <> "" Then
  410.             If InStr(outfile$, ".") = 9 Then  'got filename = 8 chars
  411.                 outfile$ = "1" + Left$(outfile$, InStr(1, outfile$, ".") - 2) + ".PRN"
  412.             Else
  413.                 outfile$ = "1" + outfile$  'otherwise, just put a 1 on the front
  414.             End If
  415.             comboutname.Text = UCase$(outfile$)         'put filename in combo box
  416.             go.SetFocus
  417.             ToAFile = True
  418.         Else
  419.             comboutname.Text = "LPT1"
  420.             outfile$ = "LPT1"
  421.             file1.SetFocus                              'set focus to file list box
  422.             ToAFile = False
  423.         End If
  424.     End Select
  425. End Sub
  426.  
  427. Sub Dir1_Change ()
  428.     file1.Path = dir1.Path
  429.     file1.SetFocus
  430. End Sub
  431.  
  432. Sub Dir1_Click ()
  433.     lastchange = dirsboxclick
  434. End Sub
  435.  
  436. Sub DoMacro (num$)
  437.     'Was Static Sub ...
  438.     Print #2, ESC$; "&f"; num$; "y2X";     'execute the macro
  439. End Sub
  440.  
  441. Sub Drive1_Change ()
  442.     dir1.Path = drive1.Drive
  443. End Sub
  444.  
  445. Sub EndMacro (num$)
  446.     'Was Static Sub ...
  447.     Print #2, ESC$; "&f"; num$; "y1X";          'Send end of macro command
  448.     Print #2, ESC$; "&f"; num$; "y9X";          'Make it temporary (10 to be permanent)
  449. End Sub
  450.  
  451. Sub File1_Click ()
  452.     'use the following line to put filename in frame
  453.     'if using a frame:
  454.     'inname.caption = "Load " + file1.filename
  455.     lastchange = fileboxclick
  456. End Sub
  457.  
  458. Sub File1_DblClick ()
  459.     Call go_click
  460. End Sub
  461.  
  462. Sub Form_Click ()
  463.     'If user clicks on the form, call the about box
  464.     Call printlogo
  465. End Sub
  466.  
  467. Sub Form_Load ()
  468.     'Set up the output combo box
  469.     comboutname.AddItem "LPT1"
  470.     comboutname.AddItem "LPT2"
  471.     comboutname.AddItem "COM1"
  472.     comboutname.AddItem "COM2"
  473.     comboutname.AddItem "file"
  474.     comboutname.Text = comboutname.List(0)    'default to LPT1
  475.     outfile$ = "LPT1"
  476.     
  477.     'Set up the Line Length combo box
  478.     linelength.AddItem "65"
  479.     linelength.AddItem "70"
  480.     linelength.AddItem "75"
  481.     linelength.AddItem "80"
  482.     linelength.Text = linelength.List(3)    'default to 80
  483.     PC.Linelen = 80                         'default to line length of 80
  484.     PC.tempmrg = 95                         'default to right side left margin of 95
  485.     'set default check-box values
  486.     tune% = -1
  487.     PC.FileTitle = -1
  488.     PC.DoHeader = -1
  489.     PC.CurDate = -1
  490.     PC.PgNumber = -1
  491.     PC.LineWrap = -1
  492.     'set some variables
  493.  
  494.     RightSide% = 1       'Reset these because of rerunning program
  495.     FirstPass% = -1      'Reset these because of rerunning program
  496.  
  497.     ESC$ = Chr$(27)                      'Standard ESC code
  498.     FF$ = Chr$(12)                       'Page Feed
  499.     LF$ = Chr$(10)                       'Line Feed
  500.     NL$ = Chr$(13) + Chr$(10)            'CR and LF
  501.     JustCount% = 0                       'Not allowing "just counting"
  502.     ' PC.Linelen = 80                    'Maximum length of line
  503.     'Setup A2 or A4 paper sizes:         'Added this in Version 1.2b
  504.     PaperAmerican = True                 'default to
  505.     PaperWidth = 175                     '  American Paper Size
  506.     ToAFile = Fale
  507. CenterForm VBBinp
  508. VBBinp.Show
  509. End Sub
  510.  
  511. Sub go_click ()
  512. 'This is the main code - everything is actually called from here
  513.  
  514. 'Code for Drive, Directory, and File selections
  515. If index >= 3 Then End
  516. If lastchange = dirsboxclick Then
  517.     dir1.Path = dir1.List(dir1.ListIndex)
  518. Else
  519.     If file1.FileName <> "" Then
  520.         ChDrive drive1.Drive
  521.         ChDir file1.Path
  522.         FileName$ = file1.FileName
  523.     Else
  524.         Msg$ = "Sorry!  You must first select a file."
  525.         Abort% = MsgBox(Msg$, 49, "No application chosen.")
  526.         If Abort% = 2 Then       'cancel button
  527.             End
  528.         End If
  529.     End If
  530. End If
  531. lastchange = fileboxclick
  532.  
  533. ReDim ptrarray&(513)                            'total number of pages (512)
  534. On Error GoTo ErrorDept                         'Error trapping
  535.  
  536. 'Ensure that we have a file name (user may have clicked DoIt without
  537. 'entering a filename)
  538.  
  539. GetName:
  540.     If Len(FileName$) = 0 Then
  541.        If tune% Then Beep
  542.         Msg$ = "Enter a file name to print: "
  543.         Title$ = "Filename"                             ' Set title.
  544.         Default$ = ""
  545.         NewName$ = InputBox$(Msg$, Title$, Default$)    ' Get user input.
  546.         If Len(NewName$) = 0 Then                       ' Check if valid.
  547.             Msg$ = "You did not input a valid Filename." + NL$
  548.             Msg$ = Msg$ + "Click on OK to End Program"
  549.             MsgBox Msg$, 0, Title$                      ' Display message.
  550.             GoTo OutHere
  551.         End If
  552.     End If
  553.  
  554.  
  555. 'Build index array for pages in FileName$
  556.    'Done with main form so show Status form and provide updates
  557.    CenterForm status
  558.    status.Show
  559.    VBBinp.Hide
  560.    
  561.    status.Print
  562.    status.Print "Available Memory: ";
  563.    status.FontItalic = True
  564.    status.Print GetFreeSpace(0)
  565.    status.FontItalic = False
  566.    
  567.    status.Print
  568.    status.Print "Reading file: ";
  569.    status.FontItalic = True
  570.    status.Print FileName$
  571.    status.FontItalic = False
  572.    Call BuildArray(ptrarray&(), Page%)          'Built pointer array
  573.  
  574.  
  575. 'Figure number of pages needed
  576.    If Page% Mod 4 Then                          'Even multiples of 4 only
  577.       Page% = Page% + (4 - Page% Mod 4)         '  correct for less
  578.    End If
  579.  
  580.    status.Print
  581.    status.Print "You will print";
  582.    status.FontItalic = True
  583.    status.Print Page% \ 4;
  584.    status.FontItalic = False
  585.    If Page% \ 4 > 1 Then
  586.     status.Print "sheets."                        'Report total number of pages
  587.    Else
  588.     status.Print "sheet."
  589.    End If
  590.    status.Print
  591.  
  592.    'JustCount% is set to false always right now
  593.    If JustCount% Then
  594.       Print "Press any key to continue, or ESC to cancel printing"
  595.       GoSub KeyIn
  596.    End If
  597.  
  598.     'Start of printing routines
  599.     Open outfile$ For Output As #2              'Open printer or output file
  600.     Call PrintSetup                             'Set up printer
  601.  
  602. 'Page parsing variables
  603.    LeftSide% = Page%
  604.    RightSide% = 1
  605.    FirstPass% = -1
  606.  
  607. Open FileName$ For Binary As #1                 'Open the input file
  608.     status.Print "Printing Side 1 to: ";        'Track what is going on
  609.     status.FontItalic = True
  610.     status.Print outfile$
  611.     status.FontItalic = False
  612.     'Status.Print
  613.  
  614. DoPass:
  615.    Bookmark% = (Page% \ 4)                      'Flag for halfway through
  616.    If Bookmark% = 0 Then Bookmark% = 1          'Force 1 if too small
  617.  
  618. 'Read text and send to printer or file
  619. 'Print the right side of the page first
  620. Do
  621.     Junk% = DoEvents()                          'yield some time to the system
  622.     If ptrarray&(RightSide% + 1) = 0 Then       'If blank, then skip it
  623.        GoTo NextPage
  624.     End If
  625.     Call DoMacro("2")                           'Start on right side
  626.     LJLocate PC.tempmrg, 0
  627.  
  628.     If PC.DoHeader Then Call Header(RightSide%) 'Header if needed
  629.     Buffer$ = Space$(ptrarray&(RightSide% + 1) - ptrarray&(RightSide%))
  630.  
  631.     Get #1, ptrarray&(RightSide%), Buffer$      'Read in a page
  632.  
  633.     If InStr(Buffer$, FF$) Then                 'If the last character is a Page Feed
  634.        Print #2, Left$(Buffer$, InStr(Buffer$, FF$) - 1); 'print only text
  635.     Else
  636.        Print #2, Buffer$;                       'Otherwise print full line
  637.     End If
  638.  
  639. NextPage:
  640.     If ptrarray&(LeftSide% + 1) = 0 Then        'Don't print blank pages
  641.        GoTo NextPage1
  642.     End If
  643.     Call DoMacro("1")                           'Reset margins for left side
  644.     LJLocate 0, 0                               'Home the cursor
  645.     If PC.DoHeader Then Call Header(LeftSide%)  'Header if needed
  646.     'Setup buffer for input
  647.     Buffer$ = Space$(ptrarray&(LeftSide% + 1) - ptrarray&(LeftSide%))
  648.     If LeftSide% = 0 Then                       'If pointing at blank page, skip
  649.        GoTo NextPage1
  650.     End If
  651.     Get #1, ptrarray&(LeftSide%), Buffer$       'Read in a page
  652.  
  653.     If InStr(Buffer$, FF$) Then                 'if the last character is a Page Feed
  654.        Print #2, Left$(Buffer$, InStr(Buffer$, FF$) - 1); 'print only text
  655.     Else                                        'print only text
  656.        Print #2, Buffer$;                       'otherwise print all
  657.     End If
  658.  
  659. NextPage1:
  660.     Print #2, FF$;                              'Page feed
  661.     LeftSide% = LeftSide% - 2                   'Calculate next page in series
  662.     RightSide% = RightSide% + 2
  663.     Bookmark% = Bookmark% - 1                   'Track our progress
  664.  
  665. Loop Until Bookmark% = 0                        'Print pages until halfway through
  666.  
  667. 'Pause between sides to allow for paper reinsertion
  668.     If FirstPass% Then                          'If side one, prompt and get 2nd side
  669.         FirstPass% = 0                          'Flag for second pass
  670.         
  671.         If ToAFile = False Then                 'don't display the wait msg if going to a file
  672.             If tune% Then Beep
  673.             Msg$ = "First Pass has been Completed." + NL$
  674.             Msg$ = Msg$ + "Insert paper back in tray and Click OK." + NL$
  675.             Msg$ = Msg$ + "(Or cancel to abort.)"
  676.             Abort% = MsgBox(Msg$, 49, "Continue?")
  677.             If Abort% = 2 Then                      'cancel button
  678.                 GoTo PrtReset                       'Reset printer and end program
  679.             End If
  680.         Else
  681.             'now close the outfile$ and reopen the second one for pass 2
  682.             Close #2
  683.             outfile$ = "2" + Right$(outfile$, Len(outfile$) - 1)
  684.             Open outfile$ For Output As #2              'Open printer or output file
  685.         End If
  686.         status.Print                            'Report on progress
  687.         status.Print "Printing Side 2 to: ";
  688.         status.FontItalic = True
  689.         status.Print outfile$
  690.         status.FontItalic = False
  691.         status.Print
  692.         GoTo DoPass
  693.     End If                                      'End of first pass
  694.     'Printing is done now
  695.     Msg$ = "Printing completed."
  696.     If tune% Then Beep
  697.     MsgBox Msg$, 64, "Done"
  698.  
  699. PrtReset:
  700.     Print #2, ESC$; "E";                        'Reset laserjet
  701.  
  702. OutHere:
  703.     Close                                       'Close all files
  704.     Reset                                       'flush the buffers
  705.     Unload status
  706.     CenterForm VBBinp
  707.     VBBinp.Show
  708.     'CenterForm VBBook
  709.     'VBBook.Show
  710.     
  711.     Exit Sub
  712.     'End                                         'We now restart instead of ending
  713.  
  714. 'Error handler
  715. ErrorDept:
  716.     Beep
  717.     Msg$ = "*** Error ***" + NL$
  718.     Select Case Err
  719.       Case 482
  720.          Msg$ = Msg$ + "Printer error."
  721.       Case 68
  722.          Msg$ = Msg$ + "Device is unavailable."
  723.       Case 71
  724.          Msg$ = Msg$ + "Insert a disk in the drive and close the door."
  725.       Case 57
  726.          Msg$ = Msg$ + "Device Input/Output Error (Check Printer!)."
  727.       Case 61
  728.          Msg$ = Msg$ + "Disk is full."
  729.       Case 64, 52
  730.         Msg$ = Msg$ + "That filename is illegal."
  731.       Case 76
  732.         Msg$ = Msg$ + "That path doesn't exist."
  733.       Case 54
  734.         Msg$ = Msg$ + "Can't open your file for that type of access."
  735.       Case 55
  736.         Msg$ = Msg$ + "This file is already open."
  737.       Case 62
  738.         Msg$ = Msg$ + "This file has a nonstandard end-of-file marker" + NL$
  739.         Msg$ = Msg$ + "or an attempt was made to read beyond the end-" + NL$
  740.         Msg$ = Msg$ + "of-file marker."
  741.       Case Else
  742.          Msg$ = Msg$ + "Error number " + Str$(Err)
  743.       End Select
  744.       GoSub AWayOut
  745.       Resume
  746.  
  747. AWayOut:
  748.    Abort% = MsgBox(Msg$, 17, "ERROR")
  749.  
  750. KeyIn:
  751.       If Abort% = 2 Then                     'If user presses Cancel, Exit
  752.          Close
  753.          Reset
  754.          GoTo restart
  755.          'End
  756.       End If
  757. Return
  758.  
  759. restart:
  760.  
  761. End Sub
  762.  
  763. Sub Header (Page%)
  764.     'Was Static Sub ...
  765.     hdr$ = Space$(PC.Linelen)                     'Create a string to print
  766.    
  767.     If PC.FileTitle Then                          'Print the filename
  768.         Mid$(hdr$, (PC.Linelen \ 2) - (Len(FileName$) \ 2)) = UCase$(FileName$)
  769.     End If
  770.  
  771.     If PC.PgNumber Then                           'Print the current page
  772.         PTemp$ = "Page" + Str$(Page%)
  773.         If Page% Mod 2 Then
  774.             Mid$(hdr$, PC.Linelen - Len(PTemp$)) = PTemp$ 'odd page, right side
  775.         Else
  776.             Mid$(hdr$, 1) = PTemp$               'even page, left side
  777.         End If
  778.     End If
  779.  
  780.     If PC.CurDate Then                            'Print the current date
  781.         If Page% Mod 2 Then
  782.             Mid$(hdr$, 1) = Date$                'even page, left side
  783.         Else
  784.             Mid$(hdr$, PC.Linelen - Len(Date$)) = Date$  'odd page, right side
  785.         End If
  786.     End If
  787.     Print #2, hdr$                               'Print the Header
  788.     Print #2,                                    ' and skip a line for readability
  789.  
  790. End Sub
  791.  
  792. Sub Label1_load ()
  793.     'This section is not used at this time
  794.     Print String$(80, 61)
  795.     Print "VBBook - Booklet Printing Utility"
  796.     Print
  797.     Print "Converted to Visual Basic by Dennis Scott"
  798.     Print String$(80, 61)
  799. End Sub
  800.  
  801. Sub Linelength_Change ()
  802.     'Prevent the user from entering a value over 90 (Changed in version 1.2b for A4 paper)
  803.     If Val(linelength.Text) > 80 Then
  804.         If PaperAmerican Then
  805.             linelength.Text = "80"
  806.         Else
  807.             If Val(linelength.Text) > 90 Then
  808.                 linelength.Text = "90"
  809.             End If
  810.         End If
  811.     End If
  812.     'If the user just typed the value into the box then compute it here
  813.     PC.Linelen = Val(linelength.Text)               'convert string to number
  814.     If PaperAmerican Then
  815.         'Compute temp right margin, 95 if 80 linelength
  816.         PC.tempmrg = (110 - PC.Linelen - 15) + 80
  817.     Else
  818.         PC.tempmrg = (110 - PC.Linelen - 15) + 95       'Compute temp right margin
  819.     End If
  820. End Sub
  821.  
  822. Sub Linelength_Click ()
  823.     'Allow line lengths upto 80
  824.     'We prevent the line length from being over 90 with Linelength.Change
  825.     PC.Linelen = Val(linelength.Text)               'convert string to number
  826.     PC.tempmrg = (110 - PC.Linelen - 15) + 80       'Compute temp right margin
  827.     'values are (PC.Linelen,PC.tempmrg): 90,85 ;80,95; 75,100; 70,105; 65,110
  828.     'of course values will be different for other line lengths
  829. End Sub
  830.  
  831. Sub LJLocate (x%, Y%)                'Laser Jet cursor locate
  832.     'Was Static Sub ...
  833.     Temp$ = ESC$ + "&a" + LTrim$(Str$(Y%)) + "r" + LTrim$(Str$(x%)) + "C"
  834.     Print #2, Temp$;
  835. End Sub
  836.  
  837. Sub Picture1_Click ()
  838.     Call printlogo                          'Show the "about" box
  839. End Sub
  840.  
  841. Sub printlogo ()                  'Banner logo
  842.     'Was Static Sub ...
  843.     Msg$ = "             VB Book Ver 1.3" + NL$
  844.     Msg$ = Msg$ + "     Converted to Visual Basic" + NL$
  845.     Msg$ = Msg$ + "             by Dennis Scott." + NL$
  846.     Msg$ = Msg$ + NL$
  847.     Msg$ = Msg$ + "Send Comments/Suggestions to:" + NL$
  848.     Msg$ = Msg$ + "               CompuDirect" + NL$
  849.     Msg$ = Msg$ + "             7711 Butler Road" + NL$
  850.     Msg$ = Msg$ + "             Myrtle Beach, SC" + NL$
  851.     Msg$ = Msg$ + "               (803)650-7460" + NL$
  852.     MsgBox Msg$, 0, "About VB Book"
  853. End Sub
  854.  
  855. Sub PrintSetup ()                               'Send codes to prepare printer
  856.     Print #2, ESC$; "E";                        'Reset laserjet (simple isn't it!)
  857.     Print #2, ESC$; "&l1o5.45C";                'Select lineprinter font"
  858.     Print #2, ESC$; "(s0p16.66H";               '  and pitch
  859.     Print #2, ESC$; "&l0L";                     'Turn off page feed at 66 lines
  860.  
  861.     If PC.LineWrap Then                          'Wrap lines > 80 chars
  862.        Print #2, ESC$; "&s0C";
  863.     End If
  864.  
  865.     Print #2, ESC$; "&l2E";                     'Top margin 2 lines
  866.  
  867.     Call StartMacro("1")                        'Left side macro
  868.          Print #2, ESC$; "9";                   'Reset left - right margins
  869.          Print #2, ESC$; "&a0l" + Str$(PC.Linelen) + "M"; 'set left margin 0, right Line Length
  870.     Call EndMacro("1")
  871.  
  872.     Call StartMacro("2")                        'Right side macro
  873.          Print #2, ESC$; "9";                   'Reset left - right margins
  874.          'set left margin, right 175 for A2 or 185 for A4 paper
  875.          Print #2, ESC$; "&a" + Str$(PC.tempmrg) + "l" + Str$(PaperWidth) + "M";
  876.     Call EndMacro("2")
  877.  
  878. End Sub
  879.  
  880. Sub StartMacro (num$)
  881.     'Was Static Sub ...
  882.     Print #2, ESC$; "&f"; num$; "Y";            'Macro will have an id of Num$
  883.     Print #2, ESC$; "&f0X";                     'Start the macro now
  884. End Sub
  885.  
  886.