VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Print using mulitiple fonts

by J. M. Rizzo (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

print a single line using two fonts

Rate Print using mulitiple fonts

'

' 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




Download this snippet    Add to My Saved Code

Print using mulitiple fonts Comments

No comments have been posted about Print using mulitiple fonts. Why not be the first to post a comment about Print using mulitiple fonts.

Post your comment

Subject:
Message:
0/1000 characters