Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > FileSystemObject.CreateTextFile Problem

Reply
Thread Tools

FileSystemObject.CreateTextFile Problem

 
 
spradl
Guest
Posts: n/a
 
      08-12-2003
Hi,
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"

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

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'

Any suggestions on how to solve this problem???
 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      08-12-2003
You have a number of issues here, it seems. See inline replies.


"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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"
%>





>
> 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


>
> 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


 
Reply With Quote
 
 
 
 
spradl
Guest
Posts: n/a
 
      08-13-2003
Sorry Ray, but I should have been more explicit...

I know that the &_ is a method to continue a string onto another line.
I am doing this on purpose to separate CSVs that are on one line of
code and separated by vbcrlf or a new filetxt.WriteLine. I wasn't
trying to show multiple lines, but multiples values for each line. I
want to separate each CSV so that I can have embedded comments in the
ASP code (not in the CSV file) about what each CSV stands for.

Finally I got thath error from my actual code and not from my example.
It should have read...
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'FILETXT.writeline'
...if I based that error off of my example data.

Anywho...
so I want to be able to loop through a set of values that are
separated by lines in the ASP code, so that I can specify comments for
each value (there are a lot per line!) that makes up one line, yet
maintain the FileSystemObject.CreateTextFile parameters of having no
breaks in the text file string.

So why doesn't this work:
text = "some, long, string" & vbcrlf
filetxt.WriteLine text

Is that not actually a string that is becoming a CSV file?
 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      08-13-2003
> text = "some, long, string" & vbcrlf
> filetxt.WriteLine text


Try it without the '& vbCrLf' - WriteLine will append a newline for you.

Alan

"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Sorry Ray, but I should have been more explicit...
>
> I know that the &_ is a method to continue a string onto another line.
> I am doing this on purpose to separate CSVs that are on one line of
> code and separated by vbcrlf or a new filetxt.WriteLine. I wasn't
> trying to show multiple lines, but multiples values for each line. I
> want to separate each CSV so that I can have embedded comments in the
> ASP code (not in the CSV file) about what each CSV stands for.
>
> Finally I got thath error from my actual code and not from my example.
> It should have read...
> Microsoft VBScript runtime error '800a01b6'
> Object doesn't support this property or method: 'FILETXT.writeline'
> ..if I based that error off of my example data.
>
> Anywho...
> so I want to be able to loop through a set of values that are
> separated by lines in the ASP code, so that I can specify comments for
> each value (there are a lot per line!) that makes up one line, yet
> maintain the FileSystemObject.CreateTextFile parameters of having no
> breaks in the text file string.
>
> So why doesn't this work:
> text = "some, long, string" & vbcrlf
> filetxt.WriteLine text
>
> Is that not actually a string that is becoming a CSV file?



 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      08-13-2003

"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Sorry Ray, but I should have been more explicit...
>
> I know that the &_ is a method to continue a string onto another line.


No, the _ character is used to continue a line of code to another line. It
does not have anything to do with strings. Like, you could do:

msgbox "Hi", _
1, _
"Title"

(Not that you'd use a msgbox in ASP...)




> I am doing this on purpose to separate CSVs that are on one line of
> code and separated by vbcrlf or a new filetxt.WriteLine. I wasn't
> trying to show multiple lines, but multiples values for each line. I
> want to separate each CSV so that I can have embedded comments in the
> ASP code (not in the CSV file) about what each CSV stands for.
>


Then just drop the &_ in lines like:
filetxt.WriteLine "one," &_ 'This is the first CSV value
Just make it:
filetxt.WriteLine "one," '''''This is the first CSV value


> Finally I got thath error from my actual code and not from my example.
> It should have read...
> Microsoft VBScript runtime error '800a01b6'
> Object doesn't support this property or method: 'FILETXT.writeline'
> ..if I based that error off of my example data.


Using the code you provided, did you get this error? Your code was like:
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)

Using that code, filetxt.writeline "whatever" should work.


 
Reply With Quote
 
spradl
Guest
Posts: n/a
 
      08-13-2003
the & vbcrlf has nothing to do with the problem. I know that it would
put in an extra line if I use it with filetxt.writeline. Did anyone
even read my question?

> Then just drop the &_ in lines like:
> filetxt.WriteLine "one," &_ 'This is the first CSV value
> Just make it:
> filetxt.WriteLine "one," '''''This is the first CSV value


I think you are missing the point of this thread. I want numerous CSVs
(comma separated values) on ONE LINE of code so that it breaks at the
appropriate time so I can have comments inside the ASP.

filetxt.WriteLine "id," &_ 'This is the product ID
"item," &_ 'This is the item
"price," &_ 'This is the price
"shipping," &_ 'This is the shipping type


Do While Not objRs.EOF 'Go through the record set
filetxt.WriteLine objRs("ID") & "," &_ 'This is the first CSV value
objRs("item") & "," &_ 'More values
objRs("price") & "," &_ 'More values
objRs("shipping") & "," &_ 'More values
objRs.MoveNext: Loop 'Move to next recordset and loop

The main point is that I want comments for each value (that makes up
one line) because there are many many values per line. The above code
is not allowed because it sees the comment as a break in the line.

> Using the code you provided, did you get this error? Your code was like:
> Set filesys = CreateObject("Scripting.FileSystemObject")
> Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
>
> Using that code, filetxt.writeline "whatever" should work.


This is all example code and not my actual script. I was using it to
convey a problem not to critique typos. I was given that error when I
tried to put all values that are on one line into a string and then
filetxt.writeline "thatString". I tried this because the string would
not include the comments.
 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      08-13-2003
See inline replies.

"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...

> I think you are missing the point of this thread. I want numerous CSVs
> (comma separated values) on ONE LINE of code so that it breaks at the
> appropriate time so I can have comments inside the ASP.
>
> filetxt.WriteLine "id," &_ 'This is the product ID
> "item," &_ 'This is the item
> "price," &_ 'This is the price
> "shipping," &_ 'This is the shipping type



The point of this thread is that your code has syntactical errors. I do
understand what you want though. Try this.

sLine = ""
sLine = sLine & "id," '''This is the product ID
sLine = sLine & "item," '''This is the item
sLine = sLine & "price," '''This is the price
'''etc.
filetxt.WriteLine sLine

''Or use aLine(4), put your values in an array, and then join with ","
before or while doing the WriteLine. It'll save .000001 seconds of
processing time.


> Do While Not objRs.EOF 'Go through the record set
> filetxt.WriteLine objRs("ID") & "," &_ 'This is the first CSV value
> objRs("item") & "," &_ 'More values
> objRs("price") & "," &_ 'More values
> objRs("shipping") & "," &_ 'More values
> objRs.MoveNext: Loop 'Move to next recordset and loop
>
> The main point is that I want comments for each value (that makes up
> one line) because there are many many values per line. The above code
> is not allowed because it sees the comment as a break in the line.


Break your code out into steps. Commenting is great, but so is making
things more followable (word?).
sLine = ""
sLine = sLine & objRS.Fields.Item(0).Value '''This is the ID
sLine = sLine & objRS.Fields.Item(1).Value '''This is the item
'''etc.




>
> > Using the code you provided, did you get this error? Your code was

like:
> > Set filesys = CreateObject("Scripting.FileSystemObject")
> > Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
> >
> > Using that code, filetxt.writeline "whatever" should work.

>
> This is all example code and not my actual script. I was using it to
> convey a problem not to critique typos. I was given that error when I
> tried to put all values that are on one line into a string and then
> filetxt.writeline "thatString". I tried this because the string would
> not include the comments.


I was not critiquing typos. I was telling you that the error indicated a
variable that did not exist in your code. It was not a critique. If you
expect continual free assistance in usenet, don't be so sensitive and snippy
when there is confusion. It can be a bit of a challenge to take completely
syntactically incorrect code and a narrated description of what's going on
and turn that into working code.

Ray at work





 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      08-14-2003

"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...

> So are you saying that you can create a string first and then
> filetxt.writeline thatSting? Also, are you saying that the error I
> recieved was becasue or syntax?


Yes and yes. I personally feel that you should use string variables for
most operations like this. It makes things easier to debug and more
manageable, and it can also make things more efficient.

f.writeline "1"
f.writeline "2"
f.writeline "3"
f.writeline "4"

vs.
s = "1" & vbCrLf & "2" & vbCrLf & "3" & vbCrLf & "4"
f.writeline s

I'd go with the second option (although I may build the string a bit
differently, but that's irrelevant).

>
>
> Sorry but I am just frustrated with this problem. The variable does
> exist in the code otherwise I wouldn't be able to filetxt.writeline
> "some,values" opposed to filetxt.writeline someString.


Post your actual code. Either, the variable exists but has not been set to
a textstream, or the variable doesn't exist.

Ray at work


 
Reply With Quote
 
spradl
Guest
Posts: n/a
 
      08-14-2003
You are right Ray. I couldn't understand why I couldn't fs.writeline a
string. I had it as..

fs.writeline = someString

Damn syntax can be so hard to miss sometimes.

Thanks for all of your help!
 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      08-14-2003
Hi spradl,

A good idea is to get into the habit of putting:

<% Option Explicit %>

at the top of all of your ASP pages. If you mistype a variable name, you
will know by the error that is returned about having a variable that is not
declared. Using Option Explicit forces you to Dim your variables, which is
a good idea. This is also something that will give you .00001 seconds of
performance increase from time to time.

Ray at work

"spradl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> You are right Ray. I couldn't understand why I couldn't fs.writeline a
> string. I had it as..
>
> fs.writeline = someString
>
> Damn syntax can be so hard to miss sometimes.
>
> Thanks for all of your help!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments