Solved

Insert line at top of existing text file

Posted on 2008-06-23
4
641 Views
Last Modified: 2009-07-29
Hi All,

I have a fixed width text file which I have created using a specification file and this is ok. Now I would like to append one(1) row of information at the top of the file which is also a fixed width only of a different length. Put simple its like having two recordsets with different fixed width length being appended to the same file.

Regards
0
Comment
Question by:tristan69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 21845908
You can modify this bit I think. It basically opens a new output file, and reads in your old one after adding the first line.

Function AddHeader(FileIn As String, FileOut As String)
Dim strTAG As String
Dim strIn As String
strTAG = "ABCXYZ"
Open FileOut For Output As #2
    Print #2, strTAG
Open FileIn For Input As #1
    Do Until EOF(1)
        Line Input #1, strIn
        Print #2, strIn
    Loop
Close #1
Close #2
End Function
0
 

Author Comment

by:tristan69
ID: 21846315
I tried this and it work, and i guess i can use this as the solution. Even though I was thinking of something more along the lines of get the first recordset write it to the text file using some kind of specification, then take the other and write it to the same file using a different specification.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 21847984
Have you tried the way your're describing? I believe the output method is destructive..meaning it overwrites the old file. You can test it as you wish. Another option would be to write your recordsets to a temp table then output the final contents to a text file.
J
0
 

Accepted Solution

by:
tristan69 earned 0 total points
ID: 21926186
Hi Guys,
Here is what the solution look like I am posting it here just in case someone wants to see.

Public Function JoinNISFiles(Header As Variant)
Dim oFS As FileSystemObject
Dim oFS1 As FileSystemObject

Dim oTS As TextStream
Dim oTS1 As TextStream

Dim vTemp

Set oFS = New FileSystemObject
Set oFS1 = New FileSystemObject
sBackupPath = CurrentProject.path & "\" & "GMP NISUPLOADS\"

Set oTS = oFS.OpenTextFile(sBackupPath & "NISFileUpload.txt", ForReading)
vTemp = oTS.ReadAll

Set oTS1 = oFS.OpenTextFile(sBackupPath & Header & ".txt", ForAppending, True)
oTS1.Write (vTemp)

End Function

Thanks to evereone who responded.

Tristan69

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question