tag:blogger.com,1999:blog-7176045.post8330467976170585970..comments2007-07-12T12:41:43.557+04:00Comments on Alex & Access: How to write out Unicode text files in VBAAlex Dybenkohttp://www.blogger.com/profile/16954512620659022712noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7176045.post-76055846124807180832007-07-12T12:41:00.000+04:002007-07-12T12:41:00.000+04:002007-07-12T12:41:00.000+04:00Thanks for update, Wayne!Thanks for update, Wayne!Alex Dybenkohttp://www.blogger.com/profile/16954512620659022712noreply@blogger.comtag:blogger.com,1999:blog-7176045.post-82188617346489501832007-07-12T12:37:00.000+04:002007-07-12T12:37:00.000+04:002007-07-12T12:37:00.000+04:00Internally, all VB strings are in Unicode format a...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.<BR/><BR/>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. <BR/><BR/>Here's the better way using the byte array mentioned above:<BR/><BR/>Sub WriteUnicodeTextFile(ByRef Path As String, _<BR/> ByRef Value As String)<BR/><BR/> Dim Buffer() As Byte<BR/> Dim FileNum As Integer<BR/> <BR/> ' Convert string to an array of bytes, preserving unicode (2bytes per character)<BR/> Buffer = Value<BR/> <BR/> FileNum = FreeFile<BR/> Open Path For Binary As FileNum<BR/> Put FileNum, , Buffer<BR/> Close FileNum<BR/><BR/>End Sub<BR/><BR/>Wayne Phillips<BR/>http://www.everythingaccess.comWayne Phillipshttp://www.blogger.com/profile/03635931018326467385noreply@blogger.com