Internally, all VB strings are in Unicode format anyway. The "put" statement converts strings to ANSI *unless* you pass the string as a byte array.
The StrConv method that Giorgio provides will work but includes much extra (unnecessary) overhead because you're essentially converting the VB unicode string (2 bytes per character) to a 4-byte per character string thus using much more memory and requiring extra processing.
Here's the better way using the byte array mentioned above:
Sub WriteUnicodeTextFile(ByRef Path As String, _ ByRef Value As String)
Dim Buffer() As Byte Dim FileNum As Integer
' Convert string to an array of bytes, preserving unicode (2bytes per character) Buffer = Value
FileNum = FreeFile Open Path For Binary As FileNum Put FileNum, , Buffer Close FileNum
2 Comments:
Internally, all VB strings are in Unicode format anyway. The "put" statement converts strings to ANSI *unless* you pass the string as a byte array.
The StrConv method that Giorgio provides will work but includes much extra (unnecessary) overhead because you're essentially converting the VB unicode string (2 bytes per character) to a 4-byte per character string thus using much more memory and requiring extra processing.
Here's the better way using the byte array mentioned above:
Sub WriteUnicodeTextFile(ByRef Path As String, _
ByRef Value As String)
Dim Buffer() As Byte
Dim FileNum As Integer
' Convert string to an array of bytes, preserving unicode (2bytes per character)
Buffer = Value
FileNum = FreeFile
Open Path For Binary As FileNum
Put FileNum, , Buffer
Close FileNum
End Sub
Wayne Phillips
http://www.everythingaccess.com
Thanks for update, Wayne!
Post a Comment
Links to this post:
Create a Link
<< Home