-1

My code is basically this:

Dim writer As New System.IO.StreamWriter("C:\file.exe")
writer.Write(Chr(CInt("&H80")))
writer.Close()

I'm writing an executable so UTF-8 is not working well for me. When I write &H80 (80) it gives me (E2 82 AC) which is the UTF-8 representation of '€'. I've tried everything, is there ANY way I can write in ANSI? What should I do?

43.52.4D.
  • 950
  • 6
  • 14
  • 28
  • 2
    "Binary" is what you're looking for. – RBarryYoung Dec 25 '12 at 03:47
  • What do you mean for 'writing an executable'. The code tries to write a single byte in a file with an exe extension. This is hardly an executable. Could you explain what are your intentions here? – Steve Dec 25 '12 at 19:11
  • @Steve are you serious? Would you rather me have posted 2KB of hex data just to prove that it's an entire executable? What I posted is something called an EXAMPLE... Anyway I solved my problem thanks for helping! – 43.52.4D. Dec 28 '12 at 03:29

1 Answers1

1

You are confusing text and binary data: the data types String and Char, which is returned by Chr, are inherently linked to an encoding and are only to be used for text.

For working with binary data, use a Byte array.

Similarly, the StreamWriter class is for writing text to a fine, not binary data. To write binary data, use the BinaryWriter class.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • Right, but the question is not very clear. How could the OP name that file an executable is beyond me. – Steve Dec 25 '12 at 19:13