I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working.
Expand|Select|Wrap|Line Numbers
- 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 Declare Function AbortPrinter Lib "winspool.drv" (ByVal _
- hPrinter As Long) As Long
- Private Declare Function GetThreadLocale Lib "kernel32" () As Long
- Public Function GetLCID(tStr As String) As Long
- '
- GetLCID = GetThreadLocale()
- '
- If GetLCID = 1033 Then '1033 for English (US) Locale ID
- '
- GetLCID = 0
- '
- ElseIf GetLCID = 2052 Then ' 2052 for Chinese (PRC) Locale ID
- '
- GetLCID = Len(tStr)
- '
- End If
- '
- End Function
- Private Sub Command1_Click()
- '
- PrintLotIDLabel "AB1234-56A", "", 1, True
- '
- End Sub
- Public Function PrintLotIDLabel(strLotId As String, strAdditionalText As String, intNumCopies As Integer, booRandomBarCode) As String
- Dim lhPrinter As Long
- Dim lReturn As Long
- Dim lpcWritten As Long
- Dim lDoc As Long
- Dim MyDocInfo As DOCINFO
- Dim i As Integer
- Dim X As Printer
- Dim booPrinterFound As Boolean
- Dim strRandomBarCode As String
- Dim strID As String
- Dim strBarcodeText As String
- Dim strData As String
- PrintLotIDLabel = ""
- If booRandomBarCode Then
- Randomize
- strRandomBarCode = ""
- For i = 1 To 10
- strRandomBarCode = strRandomBarCode & Chr(Int((90 - 65 + 1) * Rnd) + 65)
- Next i
- End If
- booPrinterFound = False
- For Each X In Printers
- If (InStr(UCase(X.DeviceName), "ZEBRA") > 0) And (InStr(UCase(X.DeviceName), "300") > 0) Then
- Set Printer = X
- booPrinterFound = True
- Exit For
- End If
- Next
- If Not booPrinterFound Then
- PrintLotIDLabel = "This PC has no printer with both 'Zebra' and '300' in the name. Labels will not print."
- Exit Function
- End If
- strLotId = UCase(strLotId)
- strID = Left(strLotId & " ", 10)
- strAdditionalText = Right(Space(20) & strAdditionalText, 21)
- lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
- MyDocInfo.pDocName = strLotId & " - BarCodeLabel"
- MyDocInfo.pOutputFile = vbNullString
- MyDocInfo.pDatatype = vbNullString
- If booRandomBarCode Then
- strLotId = strRandomBarCode
- '********************************************************************************************
- 'here if we assign chinese string to "strID variable" then it will shows ASCII characters
- 'and it's working fine with english string
- strID = "Verification Label - Scan Me"
- '********************************************************************************************
- '
- End If
- For i = 1 To intNumCopies
- lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
- Call StartPagePrinter(lhPrinter)
- strData = "^XA" & vbCrLf
- strData = strData & "^FO20,15^ATN^FD" & strID & "^FS" & vbCrLf
- strData = strData & "^FO255,20^ARN^FD" & strAdditionalText & "^FS" & vbCrLf
- strData = strData & "^FO35,60^BY3,2.5,95^B3N,N,,N,N^FD" & strLotId & "^FS" & vbCrLf
- strData = strData & "^XZ" & vbCrLf
- '
- lReturn = WritePrinter(lhPrinter, ByVal strData, Len(strData) + GetLCID(strID), lpcWritten)
- lReturn = EndPagePrinter(lhPrinter)
- lReturn = EndDocPrinter(lhPrinter)
- Next i
- lReturn = ClosePrinter(lhPrinter)
- If booRandomBarCode Then PrintLotIDLabel = strRandomBarCode
- End Function