Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

coding for printing

i would like to ask if there's anyone who can provide or suggest a code for printing in VB.

i have a program that has a menu -> file ->print

so wat should i write for the coding of my "mnuFilePrint" 's click event?
0
poeyser
Asked:
poeyser
  • 3
  • 2
1 Solution
 
FoyalCommented:
Use the Printer object to print to the default printer for the system... You can also change the default printer by selecting a printer from the Printers collection.

'set up what you want to print...

'print strings...
Printer.Print "Here is some text."

'or string variables...
S = "Here is some more text."
Printer.Print S

'use vb constants for alignment...
Printer.Print vbTab & "indented line."

'print formatted strings
Printer.Print Format(Now, "mmm dd,yyyy")

Printer.EndDoc 'print it

Look for this stuff in the help files.
There are alot of properties you can
access also with the common dialog control. (CommonDialog1.ShowPrinter)

0
 
csameer1Commented:
another important question is what you want to print?
0
 
FoyalCommented:
csameer1 is right. If you want to print some types of pictures you may need to go to the api. You can, however, print a picture which is contained in a picture box by using the printer.paintpicture method. Hope this helps.
0
 
csameer1Commented:
what do you want to print?
0
 
FoyalCommented:
Add a common dialog control to your project.

Private Sub mnuFilePrint_Click()

    On Error GoTo ErrHandler
   
    CommonDialog1.ShowPrinter
   
    PrintWhatever


ExitFilePrint:

    Exit Sub

ErrHandler:

    If Err = 32755 then Exit Sub

    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitFilePrint

End Sub

Private Sub PrintWhatever()

    On Error GoTo ErrHandler

    Printer.Print "whatever"
    Printer.EndDoc

ExitPrintWhatever:

    Exit Sub

ErrHandler:
 
    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitPrintWhatever

End Sub

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now