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