Joke Collection Website - Cold jokes - In vb, what should I do if I can't connect to the virtual printer with Open LPT1 For Output As #1? The prompt file is not found!

In vb, what should I do if I can't connect to the virtual printer with Open LPT1 For Output As #1? The prompt file is not found!

when we are programming, if we add the "print" function to the program, it will make the program more perfect and professional. Below, I provide several methods to write printing programs for your reference.

1. when using the simple print function PrintForm method provided by Visual Basic

the PrintForm method of application form? Visual Basic sends the bitmap of the current form to the printer. The advantage of this method is that it hardly needs any programming? But it also has great defects. The most prominent is when low-resolution graphics are printed on high-resolution printers? The result is unsatisfactory? It will produce serrations.

the code is as follows:

Private Sub Command1_Click? Print

me. PrintForm' prints the visible area of the form

End Sub

2. Use the Printer object

to produce complex printouts? Programming is cumbersome. The Printer object represents the default printer of the system? The Printer object supports many properties and methods supported by forms and graphic boxes? All three objects have lines and boxes. The application can draw a 1-inch square box on the Printer object with the following code. Attention? The printer measures the distance in twips. There are 144 twips per inch.

Printer.Line? 2? 144? 2? 144 -Step? 144? 144 B

Printers, slave forms and graphic boxes all have Circle, PaintPicture, print, Pset, TextHeight and TextWidth methods. Use these methods? Applications can generate high-resolution output for printers.

Print text directly, see the following code:

Printer.Print "Hello? China ComputerWorld?" There is no way to print the string

Printer object and some forms and graphic boxes?

NewPage told the printer? Has the program finished sending the current output page? The Printer object should start a new page.

EndDoc told VB? End of program creation document? VB should send it to a physical printer for printing.

KillDoc cancels the current print job. The application should terminate each print job set by EndDoc and KillDoc.

the zoom attribute is used to define the zoom factor of the printout.

the copies property is used to define the number of copies to be printed.

3. if you use RichTextBox control when programming? Then you can use the SelPrint method of the control to print the

code as follows:

Private Sub Command3_Click? SelPrint method

commondialog1.flags = cdlpdreturndc+

cdlpdnopagenums

ifrtf1.sellength = then' rtf1 is the RichTextBox control of the form

CommonDialog1.Flags = Common. Dialog1.Flags+ cdlPDAllPages

Else

CommonDialog1.Flags = CommonDialog1.Flags+ cdlPDSelection

End If

CommonDialog1.CancelError = True

On Error Resume Next

CommonDialog1.ShowPrinter

If Err.Number = cdlCancel Then Exit Sub

If Err.Number < > Then

Beep

MsgBox "Error printing file." & vbCrLf + Err.Description? vbOKOnly +vbExclamation? "Printing Error?"

exit sub

end if

printer.print ""

RTF1.selprint common dialog1.hdc' print the visible area of rtf1 control

End Sub

and set the code first? Then print. If you don't need to set it? Is it easier to use the following code?

RTF1.SelPrint Printer.hDC' print the visible area of RTF1 control

4. Can you call the OLE automation service provided by Word 97 in VB? Use the powerful printing function of Word 97 to complete VB printing

the code is as follows:

Private Sub Command4_Click? Call Word to print

dim obj word as object

const classobject = "word. application"

on error goto obj error

set obj word = createobject? CLASSOBJECT 

objWord.Visible = True

objWord.Documents.Add

With objWord

.ActiveDocument.Paragraphs.Last.Range.Bold = False

.ActiveDocument.Par A graphs. last.range.font.size = 2

. activedocument.paragraphs.last.range.font.name = "bold"

. activedocument.paragraphs.last.range.font.colorindex = = 4

. activedocument.paragraphs.last.range.text = "Am I a computer world reader?"

end with

clipboard.clear

clipboard.settext "Send data to WORD through the clipboard?"

objword.selection.paste

objword.printpreview = true' preview mode

'objWord.PrintOut' to print

'objWord.Quit' to exit word

objerror?

If Err < > 429 Then

MsgBox Str$? Err  & Error$

Set objWord = Nothing' exit

exit sub

else

resume next

end if

end sub if you cannot create a Word object.