Bug? Different Chr(XX) - Behavior in B4i

MrKim

Well-Known Member
Licensed User
Longtime User
This caused me no end of grief because I was counting on a constant being the same in all three versions of the app.

I have the following line in class globals of a b4xpages project.
Dim TestCrypt As String = $"t%yg&^${Chr(222)}${Chr(222)}${Chr(200)}${Chr(195)}"$:
In B4A and B4J, as expected, the constant is:
t%yg&^ÞÞÈÃ

In B4i I get:
t%yg&^222222200195

THERE IS NO ERROR!

B4i version is 8.30.

Additional research:
I tried setting the value when initializing. Then found the post relating to having to use HEX.
What I found:
THIS fails:
B4X:
TestCrypt = $"t%yg&^${Chr(0xDE)}${Chr(0xDE)}${Chr(0xC8)}${Chr(0xC3)}"$
= t%yg&^222222200195
THIS works:
B4X:
TestCrypt = "t%yg&^" & Chr(0xDE) & Chr(0xDE) & Chr(0xC8) & Chr(0xC3)
= t%yg&^ÞÞÈÃ
In any case there needs to be a B4X solution that works in all cases or errors. (B4XChr()?).
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Maybe this is related.
 

MrKim

Well-Known Member
Licensed User
Longtime User
Maybe this is related.
I don't think you read my most thoroughly. I looked at the page you mentioned and it solved part of my problem, but the real issue here is that CHR(XX) when used with smart string literals returns a completely erroneous result with no errors. I believe there is a secondary issue in that CHR when it DOES work will return a different value with B$A/J than it will in B4i if you don't use HEX although I am not sure about that and don't have time to test it right now. I will just use #If and handle B4i differently.
 

MrKim

Well-Known Member
Licensed User
Longtime User
I have a solution that works. That is not the issue The issue here is it is possible to write code that SHOULD work but gives different results in different versions of B4X AND gives different results if appending vs string literals and doesn't throw an error.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Smart strings are of course a super important feature.

The issue here is related to the lack of char type in iOS and not to smart strings. This causes some problems when the context isn't clear. I will check it...

A possible untested workaround:
B4X:
Dim TestCrypt As String = $"t%yg&^${"" & Chr(222)}${"" & Chr(222)}${"" & Chr(200)}${"" & Chr(195)}"$:
 

MrKim

Well-Known Member
Licensed User
Longtime User
one of the issues is what you said there needs to be:



which exists 🍻

but I agree with you that the apparent fallback action of Chr() within B4I "smart" string literals is a questionable one

personally I feel that the $" "$ operations didn't add anything that wasn't already doable with the usual string operations, and perhaps the time and effort put into implementing duplicate functionality might have been more useful applied elsewhere eg variable/optional/default/named Sub parameters

but that's just me 🍻 because I can see I am in the minority here and that there is a lot of $" love "$ about in these forums
Let me rephrase the issue: There SHOULDN'T be what logically appears to be a solution but in reality provides different answers in different compilers.:)
 
Top