
-----------------------------------
diqua
Sun Oct 16, 2005 8:28 pm

printing
-----------------------------------
all right im trying to make my project print from a file using the Microsoft common dialogs... its not working

cdlPrint.FileName = "temp.tmp"
cdlPrint.ShowPrinter


if someone could tell me how to use the common dialogs it would be greatly appreciated

btw im using VB6

-----------------------------------
GlobeTrotter
Sun Oct 16, 2005 9:24 pm


-----------------------------------
I am not familiar with printing from a file, I do know this however.  I had a similar problem when printing the form.


    On Error Resume Next 'Pressing cancel produces an error
    dlgPrint.ShowPrinter
    If Err.number = 0 Then 'Print if they click print
        Me.PrintForm
    End If


The thing is, it is not good enough to show the dialogue.  That only allows the user to change settings.  You check if they didn't press cancel, then you have to actually print it.  I'm sure there's some command for printing from a file, similar to what Me.Printform does.

-----------------------------------
Monstrosity_
Mon Oct 17, 2005 1:41 pm


-----------------------------------
On Error Resume Next 'Pressing cancel produces an error
bad habbit, and no it doesnt (not in that sense anyway).

if someone could tell me how to use the common dialogs it would be greatly appreciated
Notes: Im using CommonDialog 6.0, and the control is named CD throughout. 

Here are the basics for files:
  1. CD.ShowOpen / .ShowSave - Show the dialog, then returns once user is done.
  2. CD.CancelError - True/False depending on weither cancel was pressed.
  3. CD.FileName - The full name and path of the file selected.
  4. CD.FileTitle - The file name by itself.

The basics for printers: 
  1. Printer.Print your_string_variable_here
which will make it ALOT easier.

-----------------------------------
diqua
Mon Oct 17, 2005 7:24 pm


-----------------------------------
this my entire code thanks alot to Monstrosity_
Private Sub optPrint_Click()
    Dim intNumber As Integer, strname As String
    Open "temp.tmp" For Output As #1
        For intNumber = 0 To (lstNames.ListCount - 1)
            lstNames.Selected(intNumber) = True ' send to the file the names in the list
            strname = lstNames.Text
            Print #1, strname
        Next intNumber
    Close #1
    cdlPrint.CancelError = True
    On Error GoTo ErrHandler
    cdlPrint.ShowPrinter
    Printer.NewPage
    Open "//a/" & Printer.Port For Output As #1 ' a = printer location
        Open "temp.tmp" For Input As #2
            Do Until EOF(2)
                Input #2, strname
                Print #1, strname
            Loop
        Close #2
    Close #1
    Printer.EndDoc
ErrHandler:
    Exit Sub
End Sub

