Solved

copying plot files

Posted on 1998-01-12
3
457 Views
Last Modified: 2008-03-10
I've asked this question quite a few times - but no answer works.

I use AutoCAD to create plot files which I send either to a laser printer or to a HP inkjet plotter and these are mapped to different ports or print queues through Novell 3.12.

I store in a separate file a list of the plot files together with a number referring to how it was printed.

I want to be able to automatically send the plot file to the correct printer, but so far no solution works.

I've tried

Shell Environ$("comspec") & " /c copy /b " & c$ & " LPT" & FnStr$(i&) & ":"

which returns
This program is set to run in MS-DOS mode and cannot run while other programs are running. All other programs will close if you choose to continue.

and

f& = FreeFile
Open c$ For Input As f&
r$ = Input$(LOF(f&),f&) & vbFormFeed
Close f&
i& = OpenPrinter(p$, j&, 0)
If i& = 0 Then MsgBox "unable to open " & p$ & "!", vbOKOnly + vbExclamation + vbSystemModal: Exit Function
With doc
      .pDocName = a$
      .pOutputFile = vbNullString
      .pDataType = vbNullString
End With
i& = StartDocPrinter(j&, 1, doc)
StartPagePrinter j&
WritePrinter j&, r$, Len(r$), k&
EndPagePrinter j&
EndDocPrinter j&
ClosePrinter j&

any ideas?

0
Comment
Question by:broadbent
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mrmick
ID: 1450636
broadbent, what is the error returned by the second method (the API method)?
0
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
ID: 1450637
Instead of r$, use a byte array as your buffer.  For example, populate the buffer as follows:

Dim PrintBuf() As Byte, BLen As Long
Open c$ For Binary Access Read As f&
BLen = LOF(f&) + Len(vbFormFeed)
ReDim PrintBuf(BLen)
For i& = 0 To LOF(f&) - 1
 Get #f&, , PrintBuf(i)
Next
PrintBuf(BLen - 1) = vbFormFeed

Change the WritePrinter statement to:

WritePrinter j&, PrintBuf(0), BLen, k&

This means the declaration for WritePrinter would have to be either:
Declare Function WritePrinter Lib "winspool.drv" Alias "WritePrinter" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long

OR

Declare Function WritePrinter Lib "winspool.drv" Alias "WritePrinter" (ByVal hPrinter As Long, pBuf As Byte, ByVal cdBuf As Long, pcWritten As Long) As Long

0
 
LVL 4

Author Comment

by:broadbent
ID: 1450638
The original problem was that nothing happened

BUT this works except that line should be
         PrintBuf(Blen-1)= Asc(vbFormFeed)

I've learnt something - many thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question