|
-
Dec 26th, 2019, 09:10 AM
#11
Re: chrw error 5
Code:
Option Explicit
Private Sub Form_Load()
' Of course this works because VB6 thinks it's assigning TWO characters, not one!
Dim sUTF16 As String: sUTF16 = ChrW2(&H1F601)
Debug.Print Len(sUTF16) ' As proof, Len doesn't work. It reports 2.
' And yeah, of course this works because it's just adding to the TWO characters (which should be ONE character in UTF-16.
Dim sConct As String: sConct = " " & sUTF16 & " " 'String-Concatentation-Operators work
'
' Now, let's show that InStr, InstrRev, Mid, DON'T work.
sConct = ChrW2(&H1F601) & ChrW2(&H1F602) & ChrW2(&H1F603)
sUTF16 = ChrW2(&H1F602)
Debug.Print InStr(sConct, sUTF16) ' Prints out 3, when the correct answer is 2.
Debug.Print InStrRev(sConct, sUTF16) ' Prints out 3, when the correct answer is 2.
' Knowing our sConct character is the second character, we could do the following:
Dim sTest As String: sTest = Mid$(sConct, 2)
' But this isn't going to work at all, instead returning garbage because it cut one of our double-word characters in-two.
' I'll give you that Trim$ and StrComp probably work.
' Trim$ works because it's just looking for leading and trailing spaces.
' StrComp works because it's just comparing each of those double-word characters as two-characters-each.
'And TextControl-Prop-assignments work too (incl. visualization)
' And I've got no idea what TextBoxW1 is, obviously another work-around.
'TextBoxW1.Text = Trim$(sConct) '(as do Trim, LTrim and RTrim)
End Sub
'
' A work-around to make VB6 work with UTF-16.
' If we're willing to engage in work-arounds,
' we can make virtually any language do anything.
'
Public Function ChrW2(ByVal CharCode As Long) As String
Const POW10 As Long = 2 ^ 10
If CharCode <= &HFFFF& Then ChrW2 = ChrW$(CharCode) Else _
ChrW2 = ChrW$(&HD800& + (CharCode And &HFFFF&) \ POW10) & _
ChrW$(&HDC00& + (CharCode And (POW10 - 1)))
End Function
Regarding the rest of post #12, as stated above, it's just more hyperbole, and not worthy of a response from me. I'll let others decide how to interpret it.
Hopefully, the above code sets the record straight about what works and what doesn't.
EDIT1: And just one last thought. To call UTF-16's double-word characters "corner-cases" just isn't right. That's just another way of saying that VB6 is really UCS-2, because the difference between UCS-2 and UTF-16 is precisely these "corner-cases". That's analogous to saying that all non-one-byte characters in UTF-8 are "corner-cases", which just isn't right at all. There are many languages that deal perfectly well with UTF-8. And those that don't, clearly state that they're ASCII/ANSI, and never try to claim that they're UTF-8 compatible, but just have trouble with the "corner-cases".
Last edited by Elroy; Dec 26th, 2019 at 09:29 AM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|