iOS Question [Solved] How to use Chr()?

aeric

Expert
Licensed User
Longtime User
I am trying to use Chr to send my string to thermal printer using ESC/POS commands. I have been using many Chr() and it works in B4J and B4A. However, B4i ignores Chr and convert the unicode into numbers. How to solve this issue? It also happen when I try to display the strings in a label.
 

Attachments

  • TestChr.zip
    14.2 KB · Views: 158
Solution
use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine
Tip:
Chr(0x0027) = Chr(0x27) = Chr(39)

The issue discussed happens because there is no real char type in OBJC. You need to help the compiler:
B4X:
Dim s As String = "" & Chr(0x27)

epiCode

Active Member
Licensed User
use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
In my BLE printing library for iOs (found here) I use this method to pass strings (or characters)

B4X:
BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8"))

__________________________________________________
Di perpustakaan saya untuk pencetakan BLE untuk iOs (terdapat di sini) saya menggunakan kaedah ini untuk menghantar rentetan (atau aksara)

B4X:
BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8"))
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
As for your source, it works correctly on the label

1654457211178.png
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine
Tip:
Chr(0x0027) = Chr(0x27) = Chr(39)

The issue discussed happens because there is no real char type in OBJC. You need to help the compiler:
B4X:
Dim s As String = "" & Chr(0x27)
 
Upvote 0
Solution

aeric

Expert
Licensed User
Longtime User
Tip:
Chr(0x0027) = Chr(0x27) = Chr(39)

The issue discussed happens because there is no real char type in OBJC. You need to help the compiler:
B4X:
Dim s As String = "" & Chr(0x27)

Thanks Erel. Finally I get it to work! I can now build a B4J Print Server to print receipt for B4i app using bluetooth printer with no AirPrint support!

B4X:
Public Const eLEFT     As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x00)      ' ESC a NUL
Public Const eCENTRE   As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x01)      ' ESC a SOH
Public Const eRIGHT    As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x02)      ' ESC a STX
Public Const eCLEAR    As String = "" & Chr(0x1B) & Chr(0x40)                  ' ESC @
Public Const eLINEFEED As String = "" & Chr(0x0D) & Chr(0x0A)                  ' CR LF

I am wondering why smart string literal is not working.
B4X:
Public Const eLEFT        As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x00)}"$    ' ESC a NUL
Public Const eCENTRE      As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x01)}"$    ' ESC a SOH
Public Const eRIGHT       As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x02)}"$    ' ESC a STX
Public Const eCLEAR       As String = "" & $"${Chr(0x1B)}${Chr(0x40)}"$                ' ESC @
Public Const eLINEFEED    As String = "" & $"${Chr(0x0D)}${Chr(0x0A)}"$                ' CR LF
 
Upvote 0
Top