0

I need to write some text in a new file, the strings I have to write are command and I need the file properly formatted. The machines where I run it is linux based so the file has to be compliant to the unix standard, the end of line of windows is CR+ LF, i need it to be just LF.

Here is my code:

dim obj as object
obj = CreateObject("ADODB.Stream")
obj.Type = 2
obj.Charset = "utf-8"
obj.open()
obj.WriteText("this is a try" & vbLf) 
obj.SaveToFile( "path" ,2)

The file result contains some some character at the begin of the text file.

Can someone tell me where i'm wrong?

  • 1
    Is this really VB.NET? That is a very non-.NET way to write to a file. The characters at the beginning of the file are probably the UFT-8 [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) - 0xEFBBBF. – Mark Dec 14 '16 at 19:49
  • You're right I accidentally used a wrong tag, is vb – Marco Cuccagna Dec 14 '16 at 19:51
  • 1
    VB6 or VBA? You can edit your question to use the correct tags. Perhaps [this](http://stackoverflow.com/questions/31435662/vba-save-a-file-with-utf-8-without-bom) or [this](http://stackoverflow.com/questions/4143524/can-i-export-excel-data-with-utf-8-without-bom) will help? – Mark Dec 14 '16 at 20:01
  • it's vb6, now i changed the tag. Anyway you're probably right, i need to use utf-8 without BOM – Marco Cuccagna Dec 14 '16 at 20:04
  • 1
    Perhaps you could try a different [`Charset`](https://msdn.microsoft.com/en-us/library/ms526296(v=exchg.10).aspx)? "us-ascii" may work, depending on what characters you are writing to the file (7-bit ASCII can be read as UTF-8). – Mark Dec 14 '16 at 20:13

0 Answers0