Re: SaveSetting and Unicode
- From: "Randem" <newsgroups@xxxxxxxxxx>
- Date: Wed, 19 Nov 2008 17:36:37 -1000
Since you convert to a byte array anyway, that would be the optimum time to
save binary information to the registry and be done with all the
conversions. Much simplier also...
--
Randem Systems
The Top Inno Setup Script Generator
http://www.randem.com/innoscript.html
http://www.rndem.com/installerproblems.html
http://www.randem.com/vistainstalls.html
http://www.financialtrainingservices.org
"Eduardo" <mm@xxxxxx> wrote in message news:gg2krg$s2b$1@xxxxxxxxxxx
"mayayana" <mayaXXyana@xxxxxxxxx> escribió en el mensaje
news:ujEYOukSJHA.1908@xxxxxxxxxxxxxxxxxxxxxxx
About your question:
But doesn't that all come under the
VB standard of ASCII outside and Unicode inside?
As i said before, it saves it in Unicode format in my XP, so it seems that
it's not a general rule.
In the example that i posted i see:
2) T.h.i.s.
.i.s. .
t.h.e. .
t.e.s.t.
Two bytes per character.
In other
words, can't you just do it and trust that VB will convert
as needed?
If i leave it as i have it done now, yes, because i'm converting to
Unicode prior to save with SaveSetting and converting back from Unicode
after getting it with GetSetting.
(i'm converting it to Unicode from the UDT data to the VB String format,
that always uses Unicode. So, in fact, doing that, it doesn't matter if VB
saves as Unicode or as ASCII to the registry because i'm just using the
first byte, that both systems, Unicode and ASCII, use)
What i'm doing is:
Copy the UDT to a byte array with CopyMemory:
Dim iBytes() As Byte
Dim MyUDT as MY_UDT_TYPE
Dim MyStr as String
ReDim iBytes(LenB(MyUDT) - 1)
CopyMemory ByVal VarPtr(iBytes(0)), ByVal VarPtr(MyUDT), LenB(MyUDT)
then copy the byte array into a String:
MyStr = StrConv(iBytes, vbUnicode)
So, as i converting it to Unicode, it's using two bytes per byte in the
array.
If i don't convert it to Unicode, the code would be:
MyStr = iBytes
And it would be half the size.
But in that case i would need to rely that the two bytes will be saved in
the registry (what is to say that it will be saved in Unicode format - two
bytes per character-)
After that the next line is:
SaveSetting App.Title, "Section", Whatever, MyStr
And to read the code is:
MyStr = GetSetting(App.Title, "Section", Whatever, "")
If Len(MyStr) <> 0 Then
iBytes = StrConv(MyStr, vbFromUnicode)
' [the above line would be "iBytes = MyStr" if i saved it as Unicode]
CopyMemory ByVal VarPtr(MyUDT), ByVal VarPtr(iBytes(0)), LenB(MyUDT)
End If
It's has actually a few more lines because i perform a simple checksum to
verify that the data wasn't changed.
I realize that it's a bit counterintuitive because i say that
"StrConv(MyStr, vbFromUnicode)" wouldn't be neccesary if i saved it in
Unicode, but those convertions are from the byte array to the String
format that VB uses internally.
I've never seen any problems with software
that saves settings on both XP and 9x.
If your strings are
long enogh that you're concerned about trimming them down
then wouldn't they be better in something like a .dat file?
If you save characters you wont see any problem, because they use just the
first Unicode byte.
ASCII strings (or i believe the proper name is ANSI) use one byte per
character. 256 combinations, up to 256 different characters in theory.
Unicode uses two bytes per character, 256 * 256 = 65536 total different
characters.
When you write into a VB String variable (characters, letters), it uses
just the first byte of the two bytes per character that VB has internally
because 256 characters are enough, but VB uses Unicode internally (two
bytes per character), so it leaves a zero the second byte. And even when
VB uses two bytes per character internally (Unicode), you can't use
Unicode in VB because it is not ready for that.
But... converting from a byte array to a String, it _does_ use the two
Unicode characters if you don't use StrConv.
So, if VB saves it in the registry as Unicode and recover it as Unicode,
the two bytes will be preserved, but if it converts to ASCII prior to save
it, the second byte will be lost.
.
- Follow-Ups:
- Re: SaveSetting and Unicode
- From: Eduardo
- Re: SaveSetting and Unicode
- References:
- SaveSetting and Unicode
- From: Eduardo
- Re: SaveSetting and Unicode
- From: Randem
- Re: SaveSetting and Unicode
- From: Eduardo
- Re: SaveSetting and Unicode
- From: Randem
- Re: SaveSetting and Unicode
- From: Eduardo
- Re: SaveSetting and Unicode
- From: mayayana
- Re: SaveSetting and Unicode
- From: Eduardo
- SaveSetting and Unicode
- Prev by Date: Re: vb timer and vb form
- Next by Date: Re: SaveSetting and Unicode
- Previous by thread: Re: SaveSetting and Unicode
- Next by thread: Re: SaveSetting and Unicode
- Index(es):
Relevant Pages
|