Code: Select all
PrintN (Chr($2046))
a.s = "$2046": PrintN (Chr(Val(a.s)))
The second line prints a question mark.
How can I print "F" using the Val() of a string?
Code: Select all
PrintN (Chr($2046))
a.s = "$2046": PrintN (Chr(Val(a.s)))
Code: Select all
Debug Chr($46)
a$ = "$46"
Debug Chr(Val(a$))
Code: Select all
z$ = "$2046"
m.q = Val(z$): Debug m
n.u = m
Debug Chr(n.u)
Debug Chr(8262)
chris319 wrote:I am compiling the following as unicode:
The first line prints an uppercase "F" as expected.Code: Select all
PrintN (Chr($2046)) a.s = "$2046": PrintN (Chr(Val(a.s)))
The second line prints a question mark.
How can I print "F" using the Val() of a string?
This whole Unicode thing can be somewhat confusing at times, so I'm probably not much help here chris319,chris319 wrote:That doesn't help. I'm importing this hex number from a file generated by another application so I have to use that application's character encoding.
It works if I pass the number directly but not if I try to convert a string to a number using val(), or even to an intermediate variable.
Code: Select all
z$ = "$2046" m.q = Val(z$): Debug m n.u = m Debug Chr(n.u) Debug Chr(8262)
The character value. It can be an ASCII value, or an unicode value if the program is compiled as Unicode mode.
Code: Select all
h$="$2046" ; 8262
Debug Chr(8262) ; F
Debug Chr(Val(h$)) ; -
Code: Select all
z$ = "$2046"
m.q = Val(z$)
Debug Bin(m) ; = %10000001000110 = 14 significant bits
n.u = m
Debug Bin(n) ; still = %10000001000110 = 14 significant bits
n & %1111111111111 ; remove all bits above 13.
Debug Bin(n) ; = %0000001000110
Debug Chr(n) ; now it works
Debug Chr(8262)
No bug with Chr().Dude wrote:Seems to be a bug with Chr? This should work fine when compiled in Unicode, but I get an F and a dash.
Code: Select all
h$="$2046" ; 8262 Debug Chr(8262) ; F Debug Chr(Val(h$)) ; -
Code: Select all
h$="$2046"
MessageRequester("", Chr($2046) + #LF$ +
Chr(Val(h$)))
No, that shows F here.BasicallyPure wrote:Debug Chr(n) ; now it works
I didn't have any problems with numbers as high as $FFFF.BasicallyPure wrote: It looks like Chr() doesn't like that big of a number.
You can force it to work by masking it down to 13 binary bits.
The largest number Chr() can take is $1FFF or 8191
Code: Select all
For i = 1 To $ffff
Debug "" + i + "= (" + Hex(i) + ") : " + Chr(i)
Next
Code: Select all
n=$2046
Debug Chr(Val(StrU(n, #PB_Ascii)))
Displays wrongly F here.netmaestro wrote:Ascii or Unicode:Code: Select all
n=$2046 Debug Chr(Val(StrU(n, #PB_Ascii)))
The expected result for a unicode program, or at least a meaningful one, would be ⁆ and not F (as LJ already noted).chris319 wrote: The first line prints an uppercase "F" as expected.
Code: Select all
OpenConsole()
PrintN(Chr($044f)) ; OK
a.s = "$044f" : PrintN(Chr(Val(a.s))) ; OK
Input()
CloseConsole()
Code: Select all
Debug (Chr($044f)) ; OK
a.s = "$044f" : Debug (Chr(Val(a.s))) ; OK
Code: Select all
z$ = "$2046"
m.q = Val(z$): Debug m
n.u = m
Debug Chr(n.u) ; OK
Debug Chr(8262) ; OK
Code: Select all
h$="$2046" ; 8262
Debug Chr(8262) ; OK
Debug Chr(Val(h$)) ; OK
Is there even a suitable replacement font available to test your theory?Little John wrote:So this seems to be a limitation of Debug, or of the font that Debug uses on your or my system.
A Unicode character can only be displayed, if the used font has a glyph for it.
In many fonts, glyphs for several Unicode characters are missing.
I'm also using Lucida Console Regular 12 as my source code font. That must be the default, although I was under the impression that I had selected it. But I didn't think the debug output and requesters used the same font.luis wrote:I don't get the char above printed because the font I have selected (Lucida Console) does not have the char mapped.
You are right about the bug, and there are two funny things going here:kenmo wrote: The compiler tries to convert Chr($2046) to a character, but the character 0x2046 cannot fit in one ASCII byte, so it apparently is truncated to 0x46 ("F").