使用Visual Basic(MS Access 2000中)将原始数据发送到打印机ZPL [英] Send Raw Data to ZPL Printer using Visual Basic (MS Access 2000)

查看:385
本文介绍了使用Visual Basic(MS Access 2000中)将原始数据发送到打印机ZPL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是所有我能找到的,他们没有工作。

This is all that I can find, none of them work.

选项比较数据库 显式的选项

Option Compare Database Option Explicit

  Private Type DOCINFO
      pDocName As String
      pOutputFile As String
      pDatatype As String
  End Type

  Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
      ByVal pDefault As Long) As Long
  Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
     "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pDocInfo As DOCINFO) As Long
  Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
     pcWritten As Long) As Long

  Private Sub TEST()
      Dim lhPrinter As Long
      Dim lReturn As Long
      Dim lpcWritten As Long
      Dim lDoc As Long
      Dim sWrittenData As String
      Dim MyDocInfo As DOCINFO
      lReturn = OpenPrinter("ZDesigner LP 2844", lhPrinter, 0)
      If lReturn = 0 Then
          MsgBox "The Printer Name you typed wasn't recognized."
          Exit Sub
      End If
      MyDocInfo.pDocName = "AAAAAA"
      MyDocInfo.pOutputFile = vbNullString
      MyDocInfo.pDatatype = vbNullString
      lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
      Call StartPagePrinter(lhPrinter)
       sWrittenData = "N" & vbFormFeed
      sWrittenData = sWrittenData & "q609" & vbFormFeed
      sWrittenData = sWrittenData & "Q203,26" & vbFormFeed
      sWrittenData = sWrittenData & "B26,26,0,UA0,2,2,152,B," & Chr(34) & "603679025109" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,26,0,3,1,1,N," & Chr(34) & "SKU 6205518 MFG 6354" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,56,0,3,1,1,N," & Chr(34) & "2XIST TROPICAL BEACH" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,86,0,3,1,1,N," & Chr(34) & "STRIPE SQUARE CUT TRUNK" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,116,0,3,1,1,N," & Chr(34) & "BRICK" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,146,0,3,1,1,N," & Chr(34) & "X-LARGE" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "P1,1" & vbFormFeed
      lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
         Len(sWrittenData), lpcWritten)
      lReturn = EndPagePrinter(lhPrinter)
      lReturn = EndDocPrinter(lhPrinter)
      lReturn = ClosePrinter(lhPrinter)
  End Sub

方法2

Option Compare Database

Private Sub crtLabel()


Dim prtDevice As String
Dim strQuote As String

strQuote = Chr(34)
prtDevice = "ZDesigner LP 2844" ' whatever device Access currently has as the default. I have the user select a printer prior to printing, which sets the Access defaut printer

' open printer port
Open prtDevice For Output As #1
' initialize printer
Print #1, "OD" & vbCrLf
Print #1, "N" & vbCrLf
Print #1, "O" & vbCrLf
Print #1, "Q545,B12+23" & vbCrLf
Print #1, "q262" & vbCrLf
Print #1, "UN" & vbCrLf
Print #1, "rN" & vbCrLf
Print #1, "N" & vbCrLf
Print #1, "A4,94,3,3,1,1,N," & strQuote & "1803" & strQuote & vbCrLf
Print #1, "A36,74,3,3,1,1,N," & strQuote & "B" & strQuote & vbCrLf
Print #1, "A64,94,3,3,1,1,N," & strQuote & "079" & strQuote & vbCrLf
Print #1, "A112,8,0,2,1,1,N," & strQuote & strQuote & vbCrLf ' you can replace any string like "1803" with a string variable like SID or AID that gets passed to the sub
Print #1, "A112,32,0,3,1,1,N," & strQuote & strQuote & vbCrLf  ' same here
Print #1, "A112,64,0,1,1,1,N," & strQuote & "04/13/2009" & strQuote & vbCrLf
Print #1, "A130,100,0,1,1,1,N," & strQuote & "SWAB, NASO" & strQuote & vbCrLf
Print #1, "A4,100,0,1,1,1,N," & strQuote & "C146536" & strQuote & vbCrLf
Print #1, "B53,130,0,1,1,0,47,N," & strQuote & "2009-06868" & strQuote & vbCrLf
Print #1, "A112,188,0,1,1,1,N," & strQuote & "" & strQuote & vbCrLf
Print #1, "P1,1" & vbCrLf
Print #1, "O" & vbCrLf
' close printer port
Close #1


End Sub

没有运行函数后会发生。这就像打印机不是由code感动的。

Nothing happens after running the function. It's like the printer is not touched at all by the code.

更新 方法1是最接近我能到打印文件。执行该命令后,有一个在状态栏显示该打印机已被调用,并从我的code接收数据的打印机图标,但还是没有印刷的。帮助...

UPDATE Method 1 is the closest thing I can get to printing the file. After executing the command, there is a printer icon at the status bar show that the printer has been called and receiving data from my code, but still, no printing at all. Help...

推荐答案

好了,所以这就是我设法得到事这项工作。不是因为我想,但...它一个最佳的选择。

Okay so this is how I managed to get thing this work. Not a best option as I wanted but ... it works.

1)我用的是同样的功能,但是用C ++编写,从这里 HTTP采取: //support.microsoft.com/kb/138594/EN-US

1) I use the same function, but written in C++, taken from here http://support.microsoft.com/kb/138594/EN-US

// RawDataToPrinter - sends binary data directly to a printer
   // 
   // Params:
   //   szPrinterName - NULL terminated string specifying printer name
   //   lpData        - Pointer to raw data bytes
   //   dwCount       - Length of lpData in bytes
   // 
   // Returns: TRUE for success, FALSE for failure.
   // 
   BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
   {
     HANDLE     hPrinter;
     DOC_INFO_1 DocInfo;
     DWORD      dwJob;
     DWORD      dwBytesWritten;

     // Need a handle to the printer.
     if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
       return FALSE;

     // Fill in the structure with info about this "document."
     DocInfo.pDocName = "My Document";
     DocInfo.pOutputFile = NULL;
     DocInfo.pDatatype = "RAW";
     // Inform the spooler the document is beginning.
     if( (dwJob = StartDocPrinter( hPrinter, 1, (LPSTR)&DocInfo )) == 0 )
     {
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Start a page.
     if( ! StartPagePrinter( hPrinter ) )
     {
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Send the data to the printer.
     if( ! WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
     {
       EndPagePrinter( hPrinter );
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // End the page.
     if( ! EndPagePrinter( hPrinter ) )
     {
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Inform the spooler that the document is ending.
     if( ! EndDocPrinter( hPrinter ) )
     {
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Tidy up the printer handle.
     ClosePrinter( hPrinter );
     // Check to see if correct number of bytes were written.
     if( dwBytesWritten != dwCount )
       return FALSE;
     return TRUE;
   }

我得到的文件RAWPRN.EXE从那里,把我的英超code在一个txt文件。最后,使用shell来执行它

I got the file RAWPRN.EXE from there, put my EPL code in a txt file. Finally, use Shell to execute it

Dim RetVal
RetVal = Shell("cmd .exe /c C:\rawprint\RawPrint.exe ""ZDesigner LP 2844"" ""C:\eplcode.txt""", 1)

这篇关于使用Visual Basic(MS Access 2000中)将原始数据发送到打印机ZPL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆