tags:

views:

614

answers:

1

I am maintenance a old vb6 application that print ZPL-II.

I just find out that it has a bug if I print long lines to the printer by "Printer.Print", the lines will be trimmed to first 89 bytes/line only. It works perfect and keep lines as it is when I use Print or Copy in DOS to LPT.

Where does this behaviour come from? How can I fix it or workaround? I'd like to support all printers including LPT, USB and network printer.

PS. I double check the actual bytes sent to printer by print to a file, not LPT.

A: 

You need to use the Printer.TextWidth function and compare it to the Printer.ScaleWidth property in order to handle this issue in Visual Basic 6. It does not do automatic line wrapping for you like the DOS function.

You will make sure that the font that the printer is set too correctly match the font of the printer. This may require to use one of the "printer" fonts the driver comes with. Otherwise try to use Courier New which is a fixed space font. Otherwise the Text Width value is not going to correctly report the width.

An alternative is to use the Len string function to count the number of characters and handle the truncation yourself if it exceeds 89 characters.,

Something like like

  Do Until LineToPrint = ""
    TempD = Len(LineToPrint)
    If TempD > 89 Then
      Print Mid$(LineToPrint,1, 89)
      LineToPrint = Right$(LineToPrint,TempD-89)
    Else
      Print LineToPrint
      LineToPrint = ""
    End If
  Loop

If you like Recursive Functions you could write it like this

Private Sub PrintLine(ByVal LineToPrint As String, ByVal Width As Integer)
    TempD = Len(LineToPrint)
    If TempD > Width Then
      Printer.Print Mid$(LineToPrint, 1, Width)
      LineToPrint = Right$(LineToPrint, TempD - Width)
      PrintLine LineToPrint, Width
    Else
      Printer.Print LineToPrint
    End If
End Sub
RS Conley