473,396 Members | 1,785 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,396 software developers and data experts.

Exception when writing to a file

The following code is meant to take records from a database and write
them to a file in a comma delimited CSV format:

Set fso = CreateObject("Scripting.FileSystemObject")
filename1 = FilePath & filename1

Set f1 = fso.OpenTextFile(filename1, ForWriting, True)
f1.WriteLine "Name,School,Address Line 1,Address Line 2,Address Line
3,Address Line 4,Date Requested"

Do While Not rs.EOF

strAddress = rs("PostalAddress")
arrAdd = Split(strAddress, vbcrlf)
For i = LBound(arrAdd) to Ubound(arrAdd)
ArrGetAdd(i) = arrAdd(i)
Next

'The following line generates an exception
f1.WriteLine rs("Name") & "," & rs("School") & "," & ArrGetAdd(0) &
"," & ArrGetAdd(1) & "," & ArrGetAdd(2) & "," & ArrGetAdd(3) & "," & rs
("DateRequested")
rs.MoveNext
Loop
f1.Close
shortpath = "<BR><A HREF=" & QUOT & filename2 & QUOT & ">View CSV
File</A><BR>"

At first I thought it was something to do with the array, but it would
have said it was an 'array out of bounds' error if that was the case.

I have tested the values in the ArrGetAdd array and they seem to have
been stored fine.

Is there anything else I have missed that could be causing the error?

Thanks.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892
Jul 19 '05 #1
5 1461
My thoughts on the matter are:

1. What's your actual error?
2. I'm assuming you just didn't include the part where you're creating your
recordset, and you are in fact doing it.
3. For the address, you could skip the whole array process and just do a
Replace(theADdress, vbCrLf, ",")
4. Instead of using rs("name"), it can't hurt to use
rs.Fields.Item("name").Value
5. Make sure that your IUSR account (or the account under which this
process is running) has permissions to create and modicy files.
6. Do you have ForWriting defined in your code?

Ray at home

"Tim Chmielewski" <ch***@dcsi.net.au> wrote in message
news:Xn*****************************@130.133.1.4.. .
The following code is meant to take records from a database and write
them to a file in a comma delimited CSV format:

Set fso = CreateObject("Scripting.FileSystemObject")
filename1 = FilePath & filename1

Set f1 = fso.OpenTextFile(filename1, ForWriting, True)
f1.WriteLine "Name,School,Address Line 1,Address Line 2,Address Line
3,Address Line 4,Date Requested"

Do While Not rs.EOF

strAddress = rs("PostalAddress")
arrAdd = Split(strAddress, vbcrlf)
For i = LBound(arrAdd) to Ubound(arrAdd)
ArrGetAdd(i) = arrAdd(i)
Next

'The following line generates an exception
f1.WriteLine rs("Name") & "," & rs("School") & "," & ArrGetAdd(0) &
"," & ArrGetAdd(1) & "," & ArrGetAdd(2) & "," & ArrGetAdd(3) & "," & rs
("DateRequested")
rs.MoveNext
Loop
f1.Close
shortpath = "<BR><A HREF=" & QUOT & filename2 & QUOT & ">View CSV
File</A><BR>"

At first I thought it was something to do with the array, but it would
have said it was an 'array out of bounds' error if that was the case.

I have tested the values in the ArrGetAdd array and they seem to have
been stored fine.

Is there anything else I have missed that could be causing the error?

Thanks.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892

Jul 19 '05 #2
"Ray at <%=sLocation%>" <myFirstNameATlane34dotKOMM> wrote in
news:uD**************@TK2MSFTNGP11.phx.gbl:
My thoughts on the matter are:

1. What's your actual error?
error '80020009'
Exception occurred.
2. I'm assuming you just didn't include the part where you're
creating your recordset, and you are in fact doing it. Yes.
3. For the address, you could skip the whole array process and just
do a Replace(theADdress, vbCrLf, ",") I hadn't thought of this, thanks!

4. Instead of using rs("name"), it can't hurt to use
rs.Fields.Item("name").Value I will have a look at this, thank you.

5. Make sure that your IUSR account (or the account under which this
process is running) has permissions to create and modicy files. The page was previously working before I tried to modify the address was
written to the file.
6. Do you have ForWriting defined in your code?

Yes (defined further up):
Const ForReading = 1
Const ForWriting = 2

Thanks for your assistance.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892
Jul 19 '05 #3
"Ray at <%=sLocation%>" <myFirstNameATlane34dotKOMM> wrote in
news:uD**************@TK2MSFTNGP11.phx.gbl:

4. Instead of using rs("name"), it can't hurt to use
rs.Fields.Item("name").Value


For some reason the following occured when I tried doing that:
Microsoft OLE DB Provider for ODBC Drivers error '80040e21'

Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done.
Thanks.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892
Jul 19 '05 #4
Switch to OLEDB, and if an error still occurs, it'll at least be a little
more descriptive. www.connectionstring.com for your string. Also note that
"name" is a reserved keyword in Access and ODBC, so you should either rename
your column or bracket it in your query. "select [name],...."

Ray at home

"Tim Chmielewski" <ch***@dcsi.net.au> wrote in message
news:Xn*****************************@130.133.1.4.. .
"Ray at <%=sLocation%>" <myFirstNameATlane34dotKOMM> wrote in
news:uD**************@TK2MSFTNGP11.phx.gbl:

4. Instead of using rs("name"), it can't hurt to use
rs.Fields.Item("name").Value


For some reason the following occured when I tried doing that:
Microsoft OLE DB Provider for ODBC Drivers error '80040e21'

Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done.
Thanks.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892

Jul 19 '05 #5
"Ray at <%=sLocation%>" <myFirstNameATlane34dotKOMM> wrote in
news:Op**************@tk2msftngp13.phx.gbl:
Switch to OLEDB, and if an error still occurs, it'll at least be a
little more descriptive. www.connectionstring.com for your string.
Also note that "name" is a reserved keyword in Access and ODBC, so you
should either rename your column or bracket it in your query. "select
[name],...."

The error went away as soon as I changed the provider to OLEDB, Thanks.

--
Tim's Melbourne Flat|| GIT Groupie
http://timchuma.com || http://timchuma.com/gitgroupie/
IQC: 198344892
Jul 19 '05 #6

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

Similar topics

1
by: Abelardo Vacca | last post by:
Hello, I am currently in the process of switching our application to a N-Tier model with .NET. One of the aspects we want ot get right from the start not to worry about it after is the...
27
by: garyolsen | last post by:
In C++ what kind of unexpected conditions should be handled as exceptions? Besides dividing by 0, bad memory allocation, what're the most popular exceptions? When should not use exception,...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
14
by: Nenad Dobrilovic | last post by:
Hi, Is it possible for exception object to be aware of it's throwing? I want to log in the text file when exeption is thrown, not when the exception object is created (because I can create...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
2
by: Chris Stiefeling | last post by:
Hi, I am experiencing a strange problem. I am reading and writing xml files via XmlDocument and XmlTextWriter. In the debugger everything works fine but outside the debugger (debug or release)...
2
by: smith4894 | last post by:
{ not sure you're aware of that but there are the newsgroups for all major operating systems. you might want to try asking in the forum 'comp.os.linux.development.apps', since memory-mapped files...
7
by: Yarco | last post by:
Well, friend. Yes, I'm doing PHP. But exception is a traditional machinism in programming languages. I'm very doubt about this. In procedure language, we return error code when we meet an error. So...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

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.