Hi,
I am trying to create a dynamic CSV file via
FileSystemObjec t.CreateTextFil e. 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("S cripting.FileSy stemObject")
Set filetxt = filesys.CreateT extFile("c:\som efile.txt", True)
filetxt.WriteLi ne "This is the first CSV value," &_
"This is the second," &_
"And this is the third"
However, I would like something more like this:
filetxt.WriteLi ne "one," &_ 'This is the first CSV value
Do While Not objRs.EOF
objRs("itemNumb er") & "," &_ '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.WriteLi ne 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??? 9 11026
You have a number of issues here, it seems. See inline replies.
"spradl" <sp****@hotmail .com> wrote in message
news:74******** *************** ***@posting.goo gle.com... I am trying to create a dynamic CSV file via FileSystemObjec t.CreateTextFil e. 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("S cripting.FileSy stemObject") Set filetxt = filesys.CreateT extFile("c:\som efile.txt", True) filetxt.WriteLi ne "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.WriteLi ne "This is the first line"
filetxt.WriteLi ne "This is the second line"
filetxt.WriteLi ne "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.WriteLi ne "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.WriteLi ne "one," &_ 'This is the first CSV value Do While Not objRs.EOF objRs("itemNumb er") & "," &_ '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.WriteLi ne "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.WriteLi ne 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
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.WriteLi ne. 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.writel ine'
...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 FileSystemObjec t.CreateTextFil e parameters of having no
breaks in the text file string.
So why doesn't this work:
text = "some, long, string" & vbcrlf
filetxt.WriteLi ne text
Is that not actually a string that is becoming a CSV file?
> text = "some, long, string" & vbcrlf filetxt.WriteLi ne text
Try it without the '& vbCrLf' - WriteLine will append a newline for you.
Alan
"spradl" <sp****@hotmail .com> wrote in message
news:74******** *************** ***@posting.goo gle.com... 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.WriteLi ne. 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.writel ine' ..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 FileSystemObjec t.CreateTextFil e parameters of having no breaks in the text file string.
So why doesn't this work: text = "some, long, string" & vbcrlf filetxt.WriteLi ne text
Is that not actually a string that is becoming a CSV file?
"spradl" <sp****@hotmail .com> wrote in message
news:74******** *************** ***@posting.goo gle.com... 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.WriteLi ne. 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.WriteLi ne "one," &_ 'This is the first CSV value
Just make it:
filetxt.WriteLi ne "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.writel ine' ..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("S cripting.FileSy stemObject")
Set filetxt = filesys.CreateT extFile("c:\som efile.txt", True)
Using that code, filetxt.writeli ne "whatever" should work.
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.writeli ne. Did anyone
even read my question? Then just drop the &_ in lines like: filetxt.WriteLi ne "one," &_ 'This is the first CSV value Just make it: filetxt.WriteLi ne "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.WriteLi ne "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.WriteLi ne 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("S cripting.FileSy stemObject") Set filetxt = filesys.CreateT extFile("c:\som efile.txt", True)
Using that code, filetxt.writeli ne "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.writeli ne "thatString ". I tried this because the string would
not include the comments.
See inline replies.
"spradl" <sp****@hotmail .com> wrote in message
news:74******** *************** **@posting.goog le.com... 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.WriteLi ne "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.WriteLi ne 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.WriteLi ne 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.It em(0).Value '''This is the ID
sLine = sLine & objRS.Fields.It em(1).Value '''This is the item
'''etc. Using the code you provided, did you get this error? Your code was
like: Set filesys = CreateObject("S cripting.FileSy stemObject") Set filetxt = filesys.CreateT extFile("c:\som efile.txt", True)
Using that code, filetxt.writeli ne "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.writeli ne "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
"spradl" <sp****@hotmail .com> wrote in message
news:74******** *************** ***@posting.goo gle.com... So are you saying that you can create a string first and then filetxt.writeli ne 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.writeli ne "some,value s" opposed to filetxt.writeli ne 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
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!
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.goo gle.com... 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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 presented with a
username/password box when they view the page.
No matter what I do, when the page attempts to access the remote server, I
get a Permission Denied error. I have tried the suggestion from this page:
...
|
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")
fname.WriteLine("Hello World!")
|
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 client-side there are no problems, but if I execute
the script server-side the process stops when I call this function (I think
that the process is in loop because I must close iexplore to stop the
application).
Any thoughts?
|
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-
03/Objeto_FileSystemObject.asp, line 17
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Arquivo = objFSO.CreateTextFile("c:\Texto_teste.txt", True)
Arquivo.WriteLine("Isto é um texto." & vbcrlf & "Outra linha do texto e " &
|
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
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasdj01/html/asp0900.asp>
IIS goes out to lunch when it gets to the CreateTextFile statement in the
lines:
objFSO = server.createObject("Scripting.FileSystemObject")
| |
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 in C:\WINNT\System32
Sub Main()
Dim fs As FileSystemObject
|
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 editor. I just don't get why they get corrupted:
var ForReading = 1;
var TriStateUni = -2;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFile = fso.OpenTextFile(localPath, ForReading, false, TriStateUni);
var tempText =...
|
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 hanging indefinitely. An error
number is not returned (it just hangs on the line: Set testFile =
fso.CreateTextFile(fileName, true) ). However when I execute test 2 using
VBScript from within an Excel macro it creates the text file without any...
|
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 template page and suck some data out of a database, I then create a text file, put this information in there and then save it as a text file except that I change the extenstion to htm.
Basically I create a html file using asp and then save it.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |