none
Avoid unicode chars

    Question

  • I'm using draft printer and i want to print chr(144) to enable reverse feed. But the problem while executing is the chr(144) is converted to chrW(144) and put some unicode char in front. So the printer not working correctly.

    How can i print plain chr(144) instead of chrw(144).

    Regards

    Wednesday, March 22, 2017 4:27 AM

Answers

  • But the problem while executing is the chr(144) is converted to chrW(144) and put some unicode char in front.

    It has occurred to me that part of your issue with the Unicode extra byte
    may in fact be coming from the "j" in your string.

    A shorter path to an array of 3 Bytes with the values:

    0x1B  0x6A  0x90

    might be:

    Dim abs As Byte() = {CByte(27), CByte(Asc("j"c)), CByte(144)}
    

    - Wayne

    • Marked as answer by ackid50 Monday, March 27, 2017 5:01 AM
    Friday, March 24, 2017 8:49 PM

All replies

  • Hello ACK

    Printer control with characters is done with ASCII characters. 

    ASCII is a code table made in the time of 7 bit, the maximum was 127.

    Unicode uses in the less significant 7 bits the same code as ASCII. 

    However, above this 127 it becomes completely depending from the code table which you use. 

    It can be that your printer is based on a special language. For the from origin West European languages (Spanish, English, French, German, Portuguese, Dutch, Danish................) is table 1252 used.

    https://msdn.microsoft.com/en-us/library/cc195054.aspx

    For 144 returns Chrw the same as Chr 


    Success
    Cor



    Wednesday, March 22, 2017 7:41 AM
  • The code table 1252 (Ansi) is right

    But how can i print chr(144) in vb.net

    Thursday, March 23, 2017 4:34 AM
  • But how can i print chr(144) in vb.net

    It would help craft a recommendation if you showed us how you are
    communicating with this printer. How do you create character sequences
    to be sent to the printer? How do you send these sequences?

    Usually one sends control codes to a printer by ESCaping the character(s).

    - Wayne

    Thursday, March 23, 2017 6:21 AM
  • Here it is

    Dim ltemp1 as string = Chr(27) + "j" + Chr(144)

    'print ltemp somewhere in my code

    the problem is the Chr(144), in my vb.net convert it into ChrW(144)

    Friday, March 24, 2017 4:30 AM
  • Show the details about the statement used for printing. Consider sending the Chr(144) value using a different statement: Write.

    Friday, March 24, 2017 5:23 AM
  • Dim ltemp1 as string = Chr(27) + "j" + Chr(144)

    'print ltemp somewhere in my code

    the problem is the Chr(144), in my vb.net convert it into ChrW(144)

    String by definition is a string of Unicode characters. Have you tried
    converting it to a Char array before printing? e.g. -

    Dim ltemp1 As String = Chr(27) + "j" + Chr(144)
    Dim ch As Char() = ltemp1.ToCharArray

    - Wayne


    • Edited by WayneAKing Friday, March 24, 2017 5:52 AM
    Friday, March 24, 2017 5:52 AM
  • I assume you want to concatenate, in VB gives your operation mostly unpredictable results because with option string off is the first thing it does count everything which can be made numeric. Therefore if you concatenate use the concatenate operator instead of the plus operator.

    Dim ltemp1 as string = Chr(27) & "j" & Chr(144)



    Success
    Cor


    Friday, March 24, 2017 7:50 AM
  • String by definition is a string of Unicode characters. Have you tried

    converting it to a Char array before printing? e.g. -

    Dim ltemp1 As String = Chr(27) + "j" + Chr(144)
    Dim ch As Char() = ltemp1.ToCharArray


    In retrospect I expect that an array of bytes would be more suitable for
    your task. An array of Chars may give the same issue as String - the
    extra zero byte(s) in Unicode. Getting an array of bytes from your
    example string isn't too difficult. Your string of

    Chr(27) + "j" + Chr(144)

    is

    0x1B + 0x6A + 0x90 (as Unicode characters)

    Converting that string to an array of bytes:

    Dim ltemp1 As String = Chr(27) + "j" + Chr(144)
    Dim Un As Encoding = Encoding.Unicode
    Dim byteArray1 As Byte() = Un.GetBytes(ltemp1)
    

    yields six bytes in the array:

    0x1B + 0x00 + 0x6A + 0x00 + 0x90 + 0x00

    You can then remove the extra 0x00 bytes using any means with which
    you're comfortable. Here's a rather verbose example of creating a
    second array of bytes with those extra 0x00 bytes removed. I'm sure
    it can be done more gracefully and with less effort, but it's late
    and I can't make the effort to warp my mind into Basic mode after
    decades of assembler, C and C++ coding.

    Dim basiz = byteArray1.Length
    Dim byteArray2((basiz / 2) - 1) As Byte
    Dim idx2 = 0
    For n = 0 To byteArray1.Length - 1
        If (n + 1) Mod 2 <> 0 Then
            byteArray2(idx2) = byteArray1(n)
            idx2 = idx2 + 1
        End If
    Next
    

    This will yield a byte array with 3 bytes:

    0x1B + 0x6A + 0x90

    Then try sending that array of bytes to the printer.

    - Wayne

    Friday, March 24, 2017 9:56 AM
  • But the problem while executing is the chr(144) is converted to chrW(144) and put some unicode char in front.

    It has occurred to me that part of your issue with the Unicode extra byte
    may in fact be coming from the "j" in your string.

    A shorter path to an array of 3 Bytes with the values:

    0x1B  0x6A  0x90

    might be:

    Dim abs As Byte() = {CByte(27), CByte(Asc("j"c)), CByte(144)}
    

    - Wayne

    • Marked as answer by ackid50 Monday, March 27, 2017 5:01 AM
    Friday, March 24, 2017 8:49 PM
  • Thanks, It's working fine.
    Monday, March 27, 2017 5:02 AM