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

Writing to text files ... "overload"

I am exporting ms-access data to XML files. This works fine.

However, I need to insert one line at the top of each exported file
(i.e. a reference to the XSL file) and am having a problem with this.

First I did the following:

Export the XML file (using standard XML export) and then read the file
(line by line) and writing it out (together with the required extra
line) to a new file.

This worked OK but, with larger files, the process seems to fall over
with the message "overload". I imagine here that the buffer is full.

Can anyone suggest a way to fix this?

Or is there an easier way to simply add a line to the top of an existing
(text) file?

Maybe someone can help me here? Or can point me towards a HOWTO which
explains VBA and text-file handling in more detail?

Many thanks,
Alan Searle
Jun 5 '06 #1
5 2153
There are a bunch of ways of approaching this.

Probably the most straightforward is to write your line to a file and then
use the dos copy command to concatenate the files together.

e.g.

Sub DOSCopy(FromFiles As Variant, ByVal ToFile As String)
Dim strCmd As String
Dim strFrom As String
Dim intcount As Integer

ToFile = """" & ToFile & """"

If IsArray(FromFiles) Then
For intcount = LBound(FromFiles) To UBound(FromFiles)
strFrom = strFrom & """" & FromFiles(intcount) & """ + "
Next
strFrom = Left(strFrom, Len(strFrom) - 2)
Else
strFrom = FromFiles & " "
End If

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Call Shell(strCmd)
End Sub

The above procedure allows you to pass in n filenames in an array as the
source files and a single file as the target, it then uses the dos copy
command to oncatenate the files together.

Sample call
call doscopy(array("C:\test\1.txt", "C:\test\2.txt"), "C:\test\3.txt")

This produces a shell command like this
C:\WINNT\system32\cmd.exe /c copy "C:\test\1.txt" + "C:\test\2.txt"
"C:\test\3.txt"

--

Terry Kreft
"Alan Searle" <aj*******@xxxyahoo.com> wrote in message
news:e6**********@newsreader2.netcologne.de...
I am exporting ms-access data to XML files. This works fine.

However, I need to insert one line at the top of each exported file
(i.e. a reference to the XSL file) and am having a problem with this.

First I did the following:

Export the XML file (using standard XML export) and then read the file
(line by line) and writing it out (together with the required extra
line) to a new file.

This worked OK but, with larger files, the process seems to fall over
with the message "overload". I imagine here that the buffer is full.

Can anyone suggest a way to fix this?

Or is there an easier way to simply add a line to the top of an existing
(text) file?

Maybe someone can help me here? Or can point me towards a HOWTO which
explains VBA and text-file handling in more detail?

Many thanks,
Alan Searle

Jun 5 '06 #2
Hi Terry,

Great. This looks good and I'll give it a try.

The line I need to write should be written to the second line of the
recipient file. But I'll try writing it to the first instead and then
see what happens :-)

Thanks very much for the tip.

Cheers,
Alan.

Terry Kreft wrote:
There are a bunch of ways of approaching this.

Probably the most straightforward is to write your line to a file and then
use the dos copy command to concatenate the files together.

e.g.

Sub DOSCopy(FromFiles As Variant, ByVal ToFile As String)
Dim strCmd As String
Dim strFrom As String
Dim intcount As Integer

ToFile = """" & ToFile & """"

If IsArray(FromFiles) Then
For intcount = LBound(FromFiles) To UBound(FromFiles)
strFrom = strFrom & """" & FromFiles(intcount) & """ + "
Next
strFrom = Left(strFrom, Len(strFrom) - 2)
Else
strFrom = FromFiles & " "
End If

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Call Shell(strCmd)
End Sub

The above procedure allows you to pass in n filenames in an array as the
source files and a single file as the target, it then uses the dos copy
command to oncatenate the files together.

Sample call
call doscopy(array("C:\test\1.txt", "C:\test\2.txt"), "C:\test\3.txt")

This produces a shell command like this
C:\WINNT\system32\cmd.exe /c copy "C:\test\1.txt" + "C:\test\2.txt"
"C:\test\3.txt"

Jun 5 '06 #3
Hi Terry,

I implemented your DOCcopy suggestion (below) and it worked fine,
concatenating the files as required.

However, when I tried to open the XML file (with the extra line that I
had added with DOScopy) the browser couldn't process it.

I then went into the file and manually deleted a small square character
that had appeared at the end of the file (maybe a carriage return?) and
then it worked fine and the XML could be displayed.

Any ideas about this character? How can I get DOScopy to not create it?

If I can fix this little problem, then your idea will work for me.

Many thanks,
Alan Searle

Terry Kreft wrote:
There are a bunch of ways of approaching this.

Probably the most straightforward is to write your line to a file and then
use the dos copy command to concatenate the files together.

e.g.

Sub DOSCopy(FromFiles As Variant, ByVal ToFile As String)
Dim strCmd As String
Dim strFrom As String
Dim intcount As Integer

ToFile = """" & ToFile & """"

If IsArray(FromFiles) Then
For intcount = LBound(FromFiles) To UBound(FromFiles)
strFrom = strFrom & """" & FromFiles(intcount) & """ + "
Next
strFrom = Left(strFrom, Len(strFrom) - 2)
Else
strFrom = FromFiles & " "
End If

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Call Shell(strCmd)
End Sub

The above procedure allows you to pass in n filenames in an array as the
source files and a single file as the target, it then uses the dos copy
command to oncatenate the files together.

Sample call
call doscopy(array("C:\test\1.txt", "C:\test\2.txt"), "C:\test\3.txt")

This produces a shell command like this
C:\WINNT\system32\cmd.exe /c copy "C:\test\1.txt" + "C:\test\2.txt"
"C:\test\3.txt"

Jun 11 '06 #4
Whoops, the line

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Should be
strCmd = Environ$("COMSPEC") & " /c copy /b " _
& strFrom & ToFile
(note the /b)

otherwise it appends the dos eof character which is ASCII 26 (the
rectangular mark you see).

--

Terry Kreft
"Alan Searle" <aj*******@xxxyahoo.com> wrote in message
news:e6**********@newsreader2.netcologne.de...
Hi Terry,

I implemented your DOCcopy suggestion (below) and it worked fine,
concatenating the files as required.

However, when I tried to open the XML file (with the extra line that I
had added with DOScopy) the browser couldn't process it.

I then went into the file and manually deleted a small square character
that had appeared at the end of the file (maybe a carriage return?) and
then it worked fine and the XML could be displayed.

Any ideas about this character? How can I get DOScopy to not create it?

If I can fix this little problem, then your idea will work for me.

Many thanks,
Alan Searle

Terry Kreft wrote:
There are a bunch of ways of approaching this.

Probably the most straightforward is to write your line to a file and then use the dos copy command to concatenate the files together.

e.g.

Sub DOSCopy(FromFiles As Variant, ByVal ToFile As String)
Dim strCmd As String
Dim strFrom As String
Dim intcount As Integer

ToFile = """" & ToFile & """"

If IsArray(FromFiles) Then
For intcount = LBound(FromFiles) To UBound(FromFiles)
strFrom = strFrom & """" & FromFiles(intcount) & """ + "
Next
strFrom = Left(strFrom, Len(strFrom) - 2)
Else
strFrom = FromFiles & " "
End If

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Call Shell(strCmd)
End Sub

The above procedure allows you to pass in n filenames in an array as the
source files and a single file as the target, it then uses the dos copy
command to oncatenate the files together.

Sample call
call doscopy(array("C:\test\1.txt", "C:\test\2.txt"), "C:\test\3.txt")
This produces a shell command like this
C:\WINNT\system32\cmd.exe /c copy "C:\test\1.txt" + "C:\test\2.txt"
"C:\test\3.txt"

Jun 12 '06 #5

Terry Kreft wrote:
Whoops, the line

strCmd = Environ$("COMSPEC") & " /c copy " _
& strFrom & ToFile

Should be
strCmd = Environ$("COMSPEC") & " /c copy /b " _
& strFrom & ToFile
(note the /b)

otherwise it appends the dos eof character which is ASCII 26 (the
rectangular mark you see).

Jun 17 '06 #6

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

Similar topics

34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
7
by: Raghu | last post by:
Hello All, I need some help regarding overloading operation. Is there any way to overload typecasting? I mean if i have a piece of code as below. int a = 2: float b; b = (float)a;
0
by: bjpandapark | last post by:
Hi, I am working on my homework...and I have to do create a class where it can calculate the area of the rectangle while under these conditions.. 1. limit the width and length ...under 20...
3
by: 0infinity0 | last post by:
Why wont the operator work #include <iostream.h> class A { public: A * operator = (A * rhs) { cout << "Ptr cpy" << endl; return this;
3
by: Kim Stubberup | last post by:
I am making a script parser and I need to interpret the word AND and "replace" it with an &, so that it can be compiled at runtime with the C# compiler. My script would read e.g: if(...
14
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
2
by: BlackMustard | last post by:
hi all, i am trying to convert the string "32999" to a number, in order to compare it to other numbers and tell which one is the largest one, or if they're equal. i keep getting an overflow...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.