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

x
?
Solved

copying plot files

Posted on 1998-01-12
3
Medium Priority
?
463 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

783 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