You have a number of issues here, it seems. See inline replies.
[quoted text, click to view] "spradl" <spradl@hotmail.com> wrote in message
news:745950ab.0308121334.3b6badf2@posting.google.com...
> I am trying to create a dynamic CSV file via
> FileSystemObject.CreateTextFile. I have no problem creating the CSV
> file normally but I would like to insert comments and VBScript into
> the coding.
>
> Normally, the file would look something like this:
> Set filesys = CreateObject("Scripting.FileSystemObject")
> Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
> filetxt.WriteLine "This is the first CSV value," &_
> "This is the second," &_
> "And this is the third"
That would not be the first, second, and third line. The _ character is a
way of continuing your VB* code from line to line in your actual source
code. If you wanted separate lines in your output file, you'd either have
to do a .writeline with each string as such:
<%
filetxt.WriteLine "This is the first line"
filetxt.WriteLine "This is the second line"
filetxt.WriteLine "This is the third line"
%>
or just write it all in one WriteLine and use the VB* constant, vbCrLf for
your carriage return+line feeds, as such:
<%
filetxt.WriteLine "This is the first line" & vbCrLf & "This is the second
line" & vbCrLf & "This is the third line"
%>
[quoted text, click to view] >
> However, I would like something more like this:
> filetxt.WriteLine "one," &_ 'This is the first CSV value
> Do While Not objRs.EOF
> objRs("itemNumber") & "," &_ 'These are the rest of the values
> objRs.MoveNext: Loop
Wait, you want the comments in the CSV file, or in your code? I'm going to
assume that you mean in your code... Get rid of the &_ that you have. I'm
not sure where you got the idea to put &_ at the end of all of your lines,
but don't do that. Just use:
filetxt.WriteLine "one," 'This is the first CSV value
[quoted text, click to view] >
> I have tried creating a string first and then inputting the data like:
> text = "one," &_ 'This is the first CSV value
> Do While Not objRs.EOF
> text = text & objRs("itemName") & "," &_ 'These are the rest of the
> values
> objRs.MoveNext: Loop
> filetxt.WriteLine text
>
> However, this gave the error:
> Microsoft VBScript runtime error '800a01b6'
> Object doesn't support this property or method: 'fs.writeline'
You didn't copy the code snippet from the right place here then. Note that
your error is referring to something called "fs" but your filestream object
that you're using is called filetxt.
At the top of all of your pages that ever create in VBScript, whether it be
ASP or not, use:
Option Explicit (In <% %> if ASP)
Ray at work