• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

Cant print special characters like chr(164) or chr(165) on okidate microline

Hello Experts,
We are usingto an old vb6 App print labels,
it Works just fine so now we would like to enable to print special charactes like spanish "ñ" and others...
Can you send me an example on how to do this ?
Regards

here es a part of that vb6 code
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 tl
      Private DATA(49), data2(10, 11)
      Dim lhPrinter As Long

      Private Sub Form_Load()
          Dim lReturn As Long, x As Integer, L_144 As Integer, lpe As Integer
          Dim lDoc As Long
          Dim MyDocInfo As DOCINFO
          Dim lpcWritten As Long
          Dim sWrittenData As String
          Dim pr, a As Integer, cnt As Integer, tot_lin As Integer
          Dim w As String
          Dim w_lpt As String
          
          
          tl = 49           ' Total lines to read from text file.
          a = Get_data(tl, 1)
          tot_lin = Val(DATA(48))
          L_144 = 5  ' lineas 144avos de salto entre etiquetas.
          lpe = 9    ' lineas de salto entre etiquetas
          For cnt = 1 To tot_lin
            w_lpt = get_printer()
          
            pr = PrinterNo(w_lpt)
            Set Printer = Printers(pr)
          
            lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
            If lReturn = 0 Then
              MsgBox "The Printer Name you typed wasn't recognized."
              Exit Sub
            End If
            MyDocInfo.pDocName = "Medisoft Sticker: " + DATA(9)
            MyDocInfo.pOutputFile = vbNullString
            MyDocInfo.pDatatype = vbNullString
            lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
            Call StartPagePrinter(lhPrinter)
          
            x = Print_label(False, lpe, L_144)
            lpe = 8
            L_144 = 10  ' solo despues de la primera etiqueta se avanza pequeños renglones. Despues no.
            
            lReturn = EndPagePrinter(lhPrinter)
            lReturn = EndDocPrinter(lhPrinter)
            lReturn = ClosePrinter(lhPrinter)
            Print "Adasd"
            If cnt < tot_lin Then
              a = Get_data(tl, cnt + 1)
            End If
          Next cnt
          
          lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
          MyDocInfo.pDocName = "Medisoft final Sticker: " + DATA(9)
          MyDocInfo.pOutputFile = vbNullString
          MyDocInfo.pDatatype = vbNullString
          lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
          Call StartPagePrinter(lhPrinter)
          
          If Val(DATA(49)) = 2 Then
            Print_last_label (False)
          End If
          
          lReturn = EndPagePrinter(lhPrinter)
          lReturn = EndDocPrinter(lhPrinter)
          lReturn = ClosePrinter(lhPrinter)
          
          ' Form_Unload (1)
          End
      End Sub
Private Function Get_data(tl, ln)
  Dim a As Integer, b As Integer, w As String
  
  Open "c:\tmp\l2.txt" For Input As #1 Len = 60
  For a = 1 To ln - 1
    For b = 1 To tl
      Input #1, w
    Next b
  Next a
  For a = 1 To tl
    Input #1, w
    DATA(a) = Trim(w)
  Next a
  data2(ln, 1) = DATA(20)
  data2(ln, 2) = DATA(21)
  data2(ln, 3) = DATA(19)
  data2(ln, 4) = DATA(23)
  data2(ln, 5) = DATA(24)
  data2(ln, 6) = DATA(26)
  data2(ln, 7) = DATA(29)
  data2(ln, 8) = DATA(32)
  data2(ln, 9) = DATA(35)
  data2(ln, 10) = DATA(38)
  data2(ln, 11) = DATA(41)
  Close #1
End Function
Private Function get_printer()
  Dim a As Integer, w As String
  
  Open "c:\tmp\printer_eti.txt" For Input As #1 Len = 60
  Input #1, w
  Close #1
  w = Trim(w)
  get_printer = w
End Function

Private Function Print_label(sw_lb As Boolean, lpe As Integer, L144 As Integer)
  Dim lReturn As Long, LS_1_144 As String
  Dim lDoc As Long
  Dim MyDocInfo As DOCINFO
  Dim lpcWritten As Long, em1 As String, em2 As String, un1 As String, un2 As String
  Dim sWrittenData As String, LPI_8 As String, lpi_6 As String
  Dim a As String, x   As Integer, msg1 As String, msg2 As String, lf As Integer, a1 As Integer
  LPI_8 = Chr(27) + Chr(48)
  lpi_6 = Chr(27) + Chr(50)
  em1 = Chr(27) + Chr(69)
  em2 = Chr(27) + Chr(70)
  un1 = Chr(27) + Chr(45) + Chr(49)
  un2 = Chr(27) + Chr(45) + Chr(48)
  a = Space(0)

  msg1 = DATA(27) + " " + DATA(30) + " " + DATA(33) + " " + DATA(36) + " " + DATA(39) + " " + DATA(42)
  msg2 = Mid(msg1, 46)
  msg1 = Left(msg1, 45)

' ************** ETIQUETA DE NELLA
  'If Len(Trim(msg2)) > 0 Then
  '  sWrittenData = LPI_8 '+ Chr(15) & vbCrLf ' Dos lineas margen supeerior porque el GEBRUIK(USO) va en dos lineas
  '  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  '  lf = 1
  'Else
  '  sWrittenData = LPI_8 '+ Chr(15) & vbCrLf  ' Tres lineas de margen superior por el GEBRUIK(uso) va en una sola linea.
  '  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  '  lf = 1
  'End If
  
  sWrittenData = Space(8) + em1 + un1 + "BOTICA PARADERA" + un2 + em2 + vbCrLf + LPI_8 + Chr(15)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  lf = lpe
  
  sWrittenData = a + "Ph." + Left(DATA(15), 20) + Space(3) + Left(DATA(16), 2) + Space(3) + Left(DATA(12), 3) + "Telf: 5886648" & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  'sWrittenData = Chr(15) + vbCrLf
  'lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)


  sWrittenData = a + "Dr." + Left(DATA(10), 20) + " Date: " + Left(DATA(2), 10) + "  <" + Trim(DATA(1)) + "-" + Trim(DATA(47)) + ">" & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
             
  sWrittenData = a + Left(DATA(6), 20) + " DOB:" + Left(DATA(8), 10) & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
  sWrittenData = a + msg1 & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
             
  If Len(Trim(msg2)) > 0 Then
    sWrittenData = a + msg2 & vbCrLf
    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    lf = lf - 1
  End If
  
  sWrittenData = a + DATA(20) + " " + Left(DATA(21), 2) + " " + Left(DATA(19) + Space(30), 34) & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    
  sWrittenData = a + "Exp: " + Left(DATA(24), 10) & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    
'  sWrittenData = a & vbCrLf
 ' lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

  For a1 = 1 To lf
    sWrittenData = vbCrLf
    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  Next a1
  
  LS_1_144 = Chr(27) + Chr(37) + Chr(53) ' ADD NUMBER OF LINES 0 - 127
  sWrittenData = LS_1_144 + Chr(L144)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
 ' x = Len(DATA(33) & DATA(36) & DATA(39) & DATA(41))
 ' If x > 0 Then
 '   print_gebruik
 ' End If
  
 ' sWrittenData = Chr(18)
 ' lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

' ************** ETIQUERA DE GESINNA
'  sWrittenData = Chr(15) & vbCrLf & vbCrLf & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

'  sWrittenData = a + Space(5) + "Ph." + Left(DATA(15), 20) + Space(4) + Left(DATA(16), 2) + Space(4) + Left(DATA(12), 3) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

'  sWrittenData = a + "Dr." + Left(DATA(10), 20) + " Date: " + Left(DATA(2), 10) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
             
'  sWrittenData = a + "Rel.# " + Left(DATA(5), 12) + " DOB:" + Left(DATA(8), 10) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
             
'  sWrittenData = a + Left(DATA(6), 20) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

'  msg1 = DATA(27) + " " + DATA(30) + " " + DATA(33) + " " + DATA(36) + " " + DATA(39) + " " + DATA(42)
'  msg2 = Mid(msg1, 46)
'  msg1 = Left(msg1, 45)
  
'  sWrittenData = a + msg1 & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
             
'  lf = 2
'  If Len(Trim(msg2)) > 0 Then
'    sWrittenData = a + msg2 & vbCrLf
'    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
'    lf = lf - 1
'  End If
  
'  sWrittenData = a + DATA(20) + " " + Left(DATA(21), 2) + " " + DATA(19) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
'  sWrittenData = a + "Exp: " + Left(DATA(24), 10) + "    " + DATA(43) & vbCrLf
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    
'  sWrittenData = Chr(18)
'  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    
'  For a1 = 1 To lf
'    sWrittenData = vbCrLf
'    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
'  Next a1
  
 ' x = Len(DATA(33) & DATA(36) & DATA(39) & DATA(41))
 ' If x > 0 Then
 '   print_gebruik
 ' End If
  
  sWrittenData = lpi_6 + Chr(18)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
End Function
Private Sub print_gebruik()
  ' Usando 8 lpi tenemos 10 lineas por etiqueta. Esto es de Primera linea a primera linea.
  Dim sWrittenData As String
  Dim a As Integer, b As String
  Dim lpcWritten As Long
  Dim lReturn As Long
  
  b = Space(0)
               
  sWrittenData = b + " " & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
               
  For a = 3 To 6
    If DATA(a) <> Space(60) Then
      sWrittenData = b + DATA(24 + 3 + (a - 1) * 3) & vbCrLf
 '     MsgBox "*" & sWrittenData & "*"
      lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    Else
      sWrittenData = b + Space(60) & vbCrLf
      lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    End If
  Next a
  sWrittenData = b + DATA(19) & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
End Sub

Private Function PrinterNo(port As String) As Long
  Dim p As Printer, n As Long
  n = -1
  PrinterNo = 0
  For Each p In Printers
    n = n + 1
    
    If LCase(p.port) = LCase(port) Then
      Print Str(n) + "  " + p.DeviceName
      PrinterNo = n
      Exit For
    End If
  
    If LCase(p.DeviceName) = LCase(port) Then
      Print Str(n) + "  " + p.DeviceName
      PrinterNo = n
      Exit For
    End If
    
  Next
End Function

Private Sub Print_last_label(sw_lb As Boolean)
  Dim lReturn As Long, pf01 As String, pf02 As String, pf03 As String, pf04 As String, pf05 As String, x1
  Dim lDoc As Long, a2 As Integer, TOT As Double, tlx As Integer
  Dim MyDocInfo As DOCINFO, LPI_8 As String, lpi_6 As String
  Dim lpcWritten As Long, u1 As String, u2 As String
  Dim sWrittenData As String, sp As String, n As Integer, l As Integer, LS_1_144 As String
  Dim a As String, x   As Integer, msg1 As String, msg2 As String, lf As Integer, a1 As Integer
             
  LPI_8 = Chr(27) + Chr(48)
  lpi_6 = Chr(27) + Chr(50)
             
  u1 = Chr(27) + Chr(45) + Chr(49)
  u2 = Chr(27) + Chr(45) + Chr(48)
  
  sp = Space(1)
  a = Space(0)
  
  'LS_1_144 = Chr(27) + Chr(37) + Chr(53) ' ADD NUMBER OF LINES 0 - 127
  'sWrittenData = LS_1_144 + Chr(12)
  'lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
  n = final_sticker_header()
  
  n = Val(DATA(48))
  l = 0
  TOT = 0
  For a2 = 1 To n
    pf01 = Right(Space(10) + Str(Int(Val(data2(a2, 1)))), 4)
    pf02 = Left(data2(a2, 2) + Space(10), 2)
    pf03 = Left(data2(a2, 3) + Space(50), 20)
    pf04 = my_str(Val(data2(a2, 4)), 8)
    pf05 = Trim(data2(a2, 6)) + " " + Trim(data2(a2, 7)) + " " + Trim(data2(a2, 8)) + " " + Trim(data2(a2, 9)) + " " + Trim(data2(a2, 10)) + " " + Trim(data2(a2, 11))
    sWrittenData = a + pf01 + sp + pf02 + sp + pf03 + pf04 + sp + pf05 & vbCrLf
    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
    TOT = TOT + Val(data2(a2, 4))
    l = l + 1
    tlx = 3 ' total lineas de datos en el achter etiket.
    If l = tlx And a2 < n Then
      x1 = salto_de_sticker_final1(tlx - (l - Int(l / tlx) * tlx), True)
      l = 0
    End If
  Next a2
         
  x1 = salto_de_sticker_final2(tlx - (l - Int(l / tlx) * tlx), False)
  'If n = 1 Then
  '  lf = 5
  'Else
  '  lf = 4
  'End If
  'For a1 = 1 To lf - 2
  '  sWrittenData = vbCrLf
  '  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  'Next a1
  
  'LS_1_144 = Chr(27) + Chr(37) + Chr(53) ' ADD NUMBER OF LINES 0 - 127
  'sWrittenData = LS_1_144 + Chr(6)
  'lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
  sWrittenData = lpi_6 + Chr(18)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

End Sub
Private Function salto_de_sticker_final1(LL, H)
  Dim lReturn As Long, pf01 As String, pf02 As String, pf03 As String, pf04 As String, pf05 As String
  Dim lDoc As Long, a2 As Integer, TOT As Double, LS_1_144 As String
  Dim MyDocInfo As DOCINFO, LPI_8 As String, lpi_6 As String
  Dim lpcWritten As Long, u1 As String, u2 As String
  Dim sWrittenData As String, sp As String, n As Integer, l As Integer
  
  Dim lf As Integer, a1 As Integer
  lf = 9 + IIf(LL = 3, 0, LL - 1)
  For a1 = 1 To lf
    sWrittenData = vbCrLf
    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  Next a1

  LS_1_144 = Chr(27) + Chr(37) + Chr(53) ' ADD NUMBER OF LINES 0 - 127
  sWrittenData = LS_1_144 + Chr(1)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
  If H Then
    a1 = final_sticker_header()
  End If
End Function

Private Function salto_de_sticker_final2(LL, H)
  Dim lReturn As Long, pf01 As String, pf02 As String, pf03 As String, pf04 As String, pf05 As String
  Dim lDoc As Long, a2 As Integer, TOT As Double, LS_1_144 As String
  Dim MyDocInfo As DOCINFO, LPI_8 As String, lpi_6 As String
  Dim lpcWritten As Long, u1 As String, u2 As String
  Dim sWrittenData As String, sp As String, n As Integer, l As Integer
  
  Dim lf As Integer, a1 As Integer
  lf = 8 + IIf(LL = 3, -1, LL - 1)
  For a1 = 1 To lf
    sWrittenData = vbCrLf
    lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  Next a1

  LS_1_144 = Chr(27) + Chr(37) + Chr(53) ' ADD NUMBER OF LINES 0 - 127
  sWrittenData = LS_1_144 + Chr(36)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  
  If H Then
    a1 = final_sticker_header()
  End If
End Function
Function final_sticker_header()
  Dim lReturn As Long, pf01 As String, pf02 As String, pf03 As String, pf04 As String, pf05 As String
  Dim lDoc As Long, a2 As Integer, TOT As Double
  Dim MyDocInfo As DOCINFO, LPI_8 As String, lpi_6 As String
  Dim lpcWritten As Long, u1 As String, u2 As String, em1 As String, em2 As String
  Dim sWrittenData As String, sp As String, n As Integer, l As Integer
  Dim a As String, x   As Integer, msg1 As String, msg2 As String, lf As Integer, a1 As Integer
             
  LPI_8 = Chr(27) + Chr(48)
  lpi_6 = Chr(27) + Chr(50)
             
  u1 = Chr(27) + Chr(45) + Chr(49)
  u2 = Chr(27) + Chr(45) + Chr(48)
  
  em1 = Chr(27) + Chr(69)
  em2 = Chr(27) + Chr(70)
  
  sp = Space(2)
  a = Space(0)
    
  sWrittenData = LPI_8 '& vbCrLf & vbCrLf & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

  sWrittenData = Chr(18) + Space(8) + em1 + u1 + "BOTICA PARADERA" + u2 + em2 + vbCrLf + Chr(15)
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

  sWrittenData = a + Left(DATA(5) + Space(15), 10) + " " + Left(DATA(6), 20) + " DOB:" + Left(DATA(8), 10) & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

  pf01 = Left(DATA(47) + Space(20), 3)
  pf02 = Left(Trim(DATA(12)) + Space(20), 4)
  pf03 = Left(DATA(2) + Space(50), 22)
  pf04 = Left(DATA(16) + Space(10), 4)

  sWrittenData = Chr(15) & "Rx:" + pf01 + sp + pf02 + sp + pf03 + sp + pf04 & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)

  sp = " "
  pf01 = u1 + " Qty" + u2
  pf02 = u1 + "Un" + u2
  pf03 = u1 + "      Product       " + u2
  pf04 = u1 + " Price " + u2
  pf05 = u1 + "   Gebruik  " + u2
  sWrittenData = a + pf01 + sp + pf02 + sp + pf03 + sp + pf04 + sp + pf05 & vbCrLf
  lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
End Function
      Private Function my_str(d, le)
          Dim rp As String, x As String, l As Integer, p1 As Integer, x2 As String
          x = IIf(d = 0, "0.00", Str(d))
          If d <> 0 Then
            x = x + IIf(d - Int(d) = 0, ".00", "00")
          End If
          p1 = InStr(1, x, ".")
          x2 = Mid(x, 1, p1 + 2)
          l = Len(x2)
          rp = Space(le - l) + x2
          my_str = rp
      End Function

Open in new window

0
RGuillermo
Asked:
RGuillermo
  • 4
  • 4
  • 3
  • +2
3 Solutions
 
aikimarkCommented:
* neither chr(164) nor chr(165) are Spanish characters
* what kind of printer are you using?
* does your printer support these characters?
0
 
sarabandeCommented:
i didn't see any font chosen in your code. try to find out which fonts your label printer supports and choose one which is able to print ansi character set (or ISO-8859 oe Windows codepage 1252). then you have to find out the sequence for the printer to change the font and add it to your code.

note, if your printer normally can be used as a printer in your windows environment, you also could try to set the default font by printer setup applet.

Sara
0
 
aikimarkCommented:
What should happen if you give the my_str function a value of 1.235?  Currently, the value is truncated (=1.23) instead of rounded (=1.24).
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
aikimarkCommented:
I suspect there are also simplifications or refactorings that might be applied to your code.  For instance, the my_str() function might be simplified as:
Private Function my_str(d, le)
    my_str = Right(Space(le) & Format(d,"0.00"), le)
End Function

Open in new window

reducing ten lines of code down to one.
0
 
sarabandeCommented:
neither chr(164) nor chr(165) are Spanish characters
chr 164 is a tag sign (¤) and chr 165 is the yen currency symbol (¥) while ñ is chr 241 in the windows codepage.

from which system you get the data from?

Sara
0
 
DansDadUKCommented:
I agree with the comments made by sarabande.

You need to establish which coded-character-set or Code Page you are using, or intending to use.

Bear in mind that most printers only support certain character sets.
Modern laser devices tend to support most international character sets (such as ISO-8859-1), but dot-matrix devices support far fewer sets, and also tend to use older emulations (printer languages) than those used with laser devices.

And even with Okidata Microline devices, the supported emulations and character sets will vary from device to device; for example, with the Microline 490/491 devices:

ML 490/491 emulations/fonts/character sets
It is also quite likely that the emulation and character set cannot be changed programmatically - you'd probably have to change them via the printer's front panel buttons.
0
 
hjgodeCommented:
Hello

you are reading a txt file with an encoding X and want to print the same glyph you see in the txt file after printing. You need to a) define the encoding of the glyphs in the txt file, b) define and use a codepage (encoding) on the printer and c) replace the byte value of the incoming txt value for each 'extra' glyph (like the ~n) with the byte value of the glyph of the encoding of the printer.

See following example code pages which shows which glyph (char) is printed for which byte value for a defined code page:
code page epson
If you tell us the encodding of the txt file and the code page and printer emulation (IBM or Epson ESC/P) you use, we may help buidling the mapping table.

I have done so for another OKI printer, dbase data and VB a long time ago.
0
 
DansDadUKCommented:
@higode

>> ... which byte value for a defined code page ...

The table you reproduce only mentions National Language Variants of the 7-bit ASCII coded-character-set), which only has code-points in the (decimal) range 0 - 127 (hexadecimal 0x00 - 0x7f).

The question author appears to want to use one of the 8-bit extended-ASCII character sets, which also has code-points in the (decimal) range 128 - 255 (hexadecimal 0x80 - 0xff).

We don't yet know which printer model is the target, so don't know which character sets may be supported.
0
 
hjgodeCommented:
YES, DansDadUK, you are right. The table I have posted is only the Epson language value selection table.

As it is a Oki Microline printer I assume it supports Epson ESC/P and IBM Proprinter printing language (as all the dot-matrix printers normaly do).

The question is still, which code page is the base of the txt file having the ñ char with byte value xy and which codepage will be used on the printer.

For example, if the code page of the printer is PC850:
PC850then sending a byte value of 164 will print the glyph for the ñ.
If the code page of the printer is ISO-Latin-1 then you get another glyph printed.

So, as the question was on how to get the printer to print a ñ when getting byte value 164, the answer is to set the printer to code page 850 or use ESC/P to change the code page before printing.
0
 
RGuillermoProject ManagerAuthor Commented:
aikimark, using OKIDATA microline 320
0
 
RGuillermoProject ManagerAuthor Commented:
aikimark, good remark on my_str function, I really dont know what the original programmer attemped but we will pay attention to that too... thank you.
0
 
RGuillermoProject ManagerAuthor Commented:
Sara, This is a very old legacy App still working fine,,,, it is getting the data from a vpf9 database
0
 
sarabandeCommented:
then the visual foxpro database is using codepage 850 (default codepage of a "dos" shell) as shown by hjgode.

if we assume that the printer prints windows codepage 1252 by default, you could try to replace all occurrences of char 164 (what is a lower-case ñ in cp 850) in your strings by char 241 (ñ in cp 1252) and char 165 (Ñ in cp 850) by char 209 (Ñ in cp 1252) before printing the string.

Sara
0
 
sarabandeCommented:
you could use the string replace function to do replacement of some special characters.

if you have more than a few characters to replace you better would do a full encoding like:

           
 Dim buffer As Byte() = ASCIIEncoding.GetEncoding(850).GetBytes(udpstring)
            Dim Ansi As Encoding = Encoding.GetEncoding(1252)
            Dim ascii As Encoding = Encoding.GetEncoding(850)
            Dim result As Byte() = Encoding.Convert(ascii, Ansi, buffer)

            Debug.Print(Ansi.GetString(buffer))

Open in new window


Sara
0
 
hjgodeCommented:
As you are using the windows spooler I am not sure if the data placed in the spooler will not go thru the driver. At least StartPage/EndPage will translate to driver-specific printer commands (0x0c, FF).

Further you are using a string buffer for WritePrinter(). That may be encoded from UTF8 (string standard encoding) to Byte and so uses the wrong encoding.

I would go with a printer driver PASSTHRU, that means that the driver will not handle anything of your data and you have to encode everything yourself using Byte buffers (byte array). That was the way I did in the past as the encoding from dbase to access mdb to OKI drived me crazy.
0
 
RGuillermoProject ManagerAuthor Commented:
Thanks to all Experts!!!
great advice as always!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now