• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

How print to IFR port from Windows CE?

I am using Visual Basic CE on an H/PC and want to print a simple report to a printer using the Infra-Red (IFR) port.  

I have already successfully written out a sequential file to a DOS ".txt" file using the FILE control and the "Open" and "LinePrint" commands.  Do I use the same commands with a different "Open" statement to direct the output to a printer instead of a file?  If yes, what is the syntax of the command?

In summary, how do I write/print to a printer using the IFR port? I can print to the printer using the IFR port from within Word, but I want to do it from within Visual Basic CE.

Thanks for your time,
EYoung
0
eyoung
Asked:
eyoung
  • 4
  • 4
1 Solution
 
Erick37Commented:
Why not use the Printer Common Dialog box to select the IRF printer, then print using the Printer object?
0
 
eyoungAuthor Commented:
Erik37,

Sounds like a good idea.  How does it work?  I can't find a Printer Common Dialog box under the Project/Components menu option.  There is a Common Dialog box control for CE, but I can't find any reference to the Printer features.

Also, what is the Printer Object and how do I print using it?

Any help would be appreciated.  All I want to do is to print some lines on a piece of paper.

Thanks,
EYoung
0
 
Erick37Commented:
The component you are looking for is called the Microsoft Common Dialog Control.

Example from Books Online:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'The following example displays the Print dialog
Private Sub Command1_Click()
    Dim BeginPage, EndPage, NumCopies, i
    ' Set Cancel to True
    CommonDialog1.CancelError = True
    On Error GoTo ErrHandler 'An error is raised if the user presses the cancel button
    ' Display the Print dialog box
    CommonDialog1.ShowPrinter
    ' Get user-selected values from the dialog box
    BeginPage = CommonDialog1.FromPage
    EndPage = CommonDialog1.ToPage
    NumCopies = CommonDialog1.Copies
    For i = 1 To NumCopies
        ' Put code here to send data to the printer
    Next i
    Exit Sub
ErrHandler:
    ' User pressed the Cancel button
    Exit Sub
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Another example:

This example prints the formatted text in a RichTextBox control. To try this example, put a RichTextBox control, a CommonDialog control, and a CommandButton control on a form. Paste this code into the Click event of the CommandButton control. Then run the example.
Private Sub Command1_Click()
      CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
      If RichTextBox1.SelLength = 0 Then
            CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
      Else
            CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
      End If
      CommonDialog1.ShowPrinter
      Printer.Print ""
      RichTextBox1.SelPrint CommonDialog1.hDC
End Sub


See also the Printer object in Books Online, especially the PrinterDefault property.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
eyoungAuthor Commented:
Erik37,

Several questions:

1.  You refer to the component Microsoft Common Dialog Control. Do you mean the Microsoft "CE" Common Dialog Control?  Remember, I am using the Visual Basic CE version on an H/PC.

2.  What books online are you refering to?  Sound like a good resource.

3.  There is no "ShowPrinter" method in the CommonDialog1.ShowPrinter properties.  There may be one in standard VB but I don't see one in VB "CE".

4.  Exactly what is the syntax (example) of how to "send data to the printer?

Your example said:
    For i = 1 To NumCopies
        ' Put code here to send data to the printer
    Next i
   
What would the code look like to print "Test Line 1" to the printer?

If you can help me to print something to the printer, I would be very grateful and would double the points.

Many thanks,
EYoung
0
 
Erick37Commented:
I thought that VBCE had a common dialog, similar to that in VB Win.  It seems the MS VBCE control only supports fonts, colors, but no mention of printer control.

There are companies which sell printing components for CE:

http://www.fieldsoftware.com/PrinterCE.htm
0
 
eyoungAuthor Commented:
Erick37,

That's the answer.  I downloaded the printer control from Field Software Products and it works just great.

Thank you for your help.

Regards,
Eric Young

PS, how do I give you the points?  Your support has been through comments and not proposed answers?  I'll be out of the office until tomorrow morning.
0
 
Erick37Commented:
I'm glad it worked out for you.
Microsoft plans to add the Printer Common Dialog to future releases, but for now I suppose the easiest way is to use a third party control.
0
 
eyoungAuthor Commented:
Thanks again.  EYoung
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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