Print using mulitiple fonts
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
print a single line using two fonts
Original Author: J. M. Rizzo
Code
'
' Have you ever wanted an easy way to change fonts within a print line
' when sending output to the printer? I reciently had a requirement to
' print ascii data with embeded Barcode output on the same line.
' Since the output was being generated from a database query, it made
' sense to format the data using a proportional font (Courier New) then
' change the font after printing the ascii data. Unfortunatly, the printer object
' will only allow you to specify a font for the entire line being printed.
'
' Being an old fart programmer from way back, I remebered that Q-Basic had the
' capability to stop the print head if there was a semicolon ";" after
' the statCommand1_Click()
'
' Set up to display the Common ement. I could not find a reference to this anywhere in the VB
' documentation, but tried it anyway. Wala, it works just fine.
'
' Create a form and place a command button and add the Common Dialog control to
' the form. Then Cut and paste this code into the project.
'
' You probably will not have the Code 39 font but any other valid font name
' will work fine.
'
Private Sub Command1_Click()
'
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
'
' check for errors or cancel selected
'
If Err <> 0 Then
MsgBox Error(Err)
Exit Sub
End If
'
' reset error checking
'
On Error GoTo HaveError
'
' Set the printer font to proportional font.
'
Printer.Font = "Courier New"
Printer.FontSize = 10
'
' Print out the ASCII TEXT
' NOTE THE SEMICOLON AT THE END!!!!
' THIS TELLS THE PRINT METHOD NOT TO RETURN THE PRINTER
' HEAD FOR THE NEXT LINE.
'
Printer.Print "This is the Ascii Text ";
'
' CHANGE THE PRINTER FONT FOR UPC 39 bar code font
'
Printer.Font = "Code 39"
Printer.FontSize = 12
'
' print out the ascii text in barcode font
' Notice the Leading and trailing "*" this
' translates to the start/end barcode character
' in the Code 39 font
'
Printer.Print "*This is Bar Code Text*"
'
' close out the printer object
'
Printer.EndDoc
Exit Sub
HaveError:
MsgBox Error(Err)
Resume Next
End Sub
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.