473,382 Members | 1,329 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,382 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 2152
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.