473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

FileSystemObject.CreateTextFile Problem

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???
Jul 19 '05 #1
9 11010
You have a number of issues here, it seems. See inline replies.
"spradl" <sp****@hotmail.com> wrote in message
news:74**************************@posting.google.c 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
Jul 19 '05 #2
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?
Jul 19 '05 #3
> text = "some, long, string" & vbcrlf
filetxt.WriteLine text
Try it without the '& vbCrLf' - WriteLine will append a newline for you.

Alan

"spradl" <sp****@hotmail.com> wrote in message
news:74**************************@posting.google.c 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?

Jul 19 '05 #4

"spradl" <sp****@hotmail.com> wrote in message
news:74**************************@posting.google.c 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.
Jul 19 '05 #5
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.
Jul 19 '05 #6
See inline replies.

"spradl" <sp****@hotmail.com> wrote in message
news:74*************************@posting.google.co 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

Jul 19 '05 #7

"spradl" <sp****@hotmail.com> wrote in message
news:74**************************@posting.google.c 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
Jul 19 '05 #8
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!
Jul 19 '05 #9
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" <sp****@hotmail.com> wrote in message
news:74**************************@posting.google.c 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!

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott MacLean | last post by:
I'm pulling my hair out over this one. I've got a web page that I need to have write to another server across the network. The site in question does NOT run in anonymous mode, that is, the user is...
8
by: jessie | last post by:
This my code for practice: <html> <body> <% Response.Write("6 ") dim fs,fname set fs=CreateObject("Scripting.FileSystemObject") set fname=fs.CreateTextFile("f:\test.txt")...
2
by: MeAndI | last post by:
I've some problems with "Scripting.FileSystemObject" object If I try to create a new text file with the function myfile.CreateTextFile I have two differents result: If I execute the script...
4
by: Vilmar Brazão de Oliveira | last post by:
Hi, I got the err below, nevertheless my folders have full permissions for all. Permission denied /vilmar/ASP_JavaScript_CSS_HTML/ajudas_asp_completos/novo_asp/novo_asp_4-12-...
2
by: NeilS | last post by:
I'm developing under IIS V5.1 and testing on an ethernet with IIS hosted on WinXPPro. I am trying to implement file-upload using a polished version of the technique published in...
2
by: Stavros | last post by:
Hi all when I execute the following VB6 code in Windows 2000 and as an Administrator, everything is working fine. Project->References->"Microsoft Scripting Runtime" and scrrun.dll is located...
1
by: novadoft | last post by:
hi, i am trying to use the fileSystemObject methods to read a picture file as a text (forcefully), store it in a variable, and then i try writing it back to a file and opening it up with a text...
1
by: Iain Bishop | last post by:
I am trying to execute the following function which performs four tests to make sure the current environment is capable of uploading files. Test 1 completes ok, but test 2 results in the page...
1
by: hugobotha | last post by:
Hi All, I have a problem when saving a text file as a html file in unicode and then google index the Unicode bom as well as I can not open these files. I have a asp page that takes another asp...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.