printing
Author |
Message |
diqua
![](http://upload.wikimedia.org/wikipedia/en/5/50/Calvin_%26_Hobbes_-_Calvin.png)
|
Posted: Sun Oct 16, 2005 8:28 pm Post subject: printing |
|
|
all right im trying to make my project print from a file using the Microsoft common dialogs... its not working
code: | 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
GlobeTrotter
|
Posted: Sun Oct 16, 2005 9:24 pm Post subject: (No subject) |
|
|
I am not familiar with printing from a file, I do know this however. I had a similar problem when printing the form.
VisualBASIC: |
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. |
|
|
|
|
![](images/spacer.gif) |
Monstrosity_
|
Posted: Mon Oct 17, 2005 1:41 pm Post subject: (No subject) |
|
|
GlobeTrotter wrote: On Error Resume Next 'Pressing cancel produces an error
bad habbit, and no it doesnt (not in that sense anyway).
diqua wrote: 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. this explains better then I can.
2. CD.CancelError - Same as for the files.
3. CD.Copies - Returns or sets a the number of copies to be printed.
If you decide you need DefaultPrint to be false, read this which explains what to expect, but as long as its true, it should be ok to use methods like Me.PrintForm, or any of the Printer object's methods.
Since you dont want to print the form, theres more to explain. You will want to open "Printer.Port" the same way you would open a file, then output just as you would to a file, keeping in mind to close the object and "Printer.EndDoc".
Those are the BASICS to help you on your way. Once you play around and get the hang of things. You might want to go here and check out the other properties and methods the control has.
I've spent longer then I wished explaining this, and im not going to waste more time opening VB and checking the correctness of it, any problems with it just come back and tell me.
Edit:
Although it seems to be undocumented, theres also a method that goes like...
VisualBASIC: | Printer.Print your_string_variable_here |
which will make it ALOT easier. |
|
|
|
|
![](images/spacer.gif) |
diqua
![](http://upload.wikimedia.org/wikipedia/en/5/50/Calvin_%26_Hobbes_-_Calvin.png)
|
Posted: Mon Oct 17, 2005 7:24 pm Post subject: (No subject) |
|
|
this my entire code thanks alot to Monstrosity_
code: | 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
|
|
|
|
|
|
![](images/spacer.gif) |
|
|