0

I have a long Unicode string saved in Unicode encoding from notepad, in this form

ChrW$ (&H410) & "   " & ChrW$(&H430) & vbNewLine & ChrW$(&H42F)

etc, to end of file

If I assign the above code as the value of an Ink Edit box in code, it displays the correct Unicode chars, which is what I wanted.

But for some reason I can't find the right way to open the text file and get that to display the Unicode chars. This is probably very simple, but I've got totally confused.

What is a simple way of achieving this? Thanks

Virendra Nagda
  • 673
  • 5
  • 9
moorea21
  • 5
  • 3

1 Answers1

1

Assuming your file has the Unicode text and not VB expressions as you showed... not much to it:

Dim F As Integer
Dim Text() As Byte

F = FreeFile(0)
Open "SomeUnicode.txt" For Binary Access Read As #F
'File is UTF-16LE, so we'll skip the BOM:
ReDim Text(LOF(F) - 3)
Get #F, 3, Text
Close #F
InkEd.Text = Text

Otherwise you'll need an expression evaluator, and you could use the Microsoft Script Control to process such expressions if you drop the $ type decorators.

Bob77
  • 13,167
  • 1
  • 29
  • 37
  • Apart from the file names and comments, thats the same code I was using before, with the exception of 'Binary Access Read As'... It now works fine, puzzled why it didnt before. Thanks! – moorea21 Dec 19 '15 at 22:12
  • @moorea21, don't be so selfish, you could at least accept his code – milevyo Dec 20 '15 at 13:18
  • I don't know what you mean – moorea21 Dec 20 '15 at 17:31
  • I suspect he is just referring to the "mark as accepted answer" box or something. Not a big deal to me but it seems to be considered proper in here. – Bob77 Dec 20 '15 at 17:44
  • Thanks Bob77, it certainly helps when someone explains themselves properly. Done – moorea21 Dec 21 '15 at 10:56
  • You can read UTF8 coded text files with ADO (yes, text files, not database files), see my [answer here](http://stackoverflow.com/questions/17698260/ms-word-vba-to-display-unicode-strings/17699668#17699668). Very easy, very correct. – Roman Plischke Dec 21 '15 at 14:53