Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add text to each line in text file

Status
Not open for further replies.

jcw5107

Technical User
Jan 31, 2007
66
US
I have some code I'm messin' with. I want to manipulate a text file before it is imported, this way I can minimize the amount of queries in my d/base....

I'm tryin' to insert the days date in each line of a text file. The problem I'm having is that the newly inserted text overwrites the existing text, insteading of moving it over per say - so that columns all stay in alignment. The text file is "fix width".
I sure hope this makes sense..!!
Any suggestion or examples..??
Thanks in advance..!!
Below is what I am working with..
jcw5107

Sub AssignedTaskReformat5()
DoCmd.Hourglass True
Dim db As DAO.Database
Dim strLine 'As Variant
Dim strType As Variant
Dim strImportFile As String
Dim strNewfile As String

strImportFile = "D:\UPSDATA\SchedWorkWANMain.txt"
strNewfile = "D:\UPSDATA\SchedWorkWANMstr.txt"

Open strImportFile For Input As #1
Open strNewfile For Output As #2

Do Until EOF(1)
Line Input #1, strLine
If Left(strLine, 2) = "E " _
Or Left(strLine, 2) = "S " _
Or Left(strLine, 2) = "P " Then
Mid(strLine, 350, 14) = Now()
End If
Print #2, strLine
Loop
Close #1
Close #2

End Sub
 




Hi,

Why not append the date to the END of each record? The position is not important, is it?

An if you already have in Input Spec in Access, it alot easier to modify, if the additional data is tacked on the end.

Skip,

[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue]
 
jcw5107,
I agree with Skip since your writting the routine to import, but...
Code:
...
Do Until EOF(1)
  Line Input #1, strLine
  If Left(strLine, 2) = "E " _
  Or Left(strLine, 2) = "S " _
  Or Left(strLine, 2) = "P " Then
    strPrefix = Left(strLine, 350)
    strAffix = Mid(strLine, 351)
  End If
  'Format string is padded to 14 characters
  Print #2, strPrefix & Format$(Now, "    mm/dd/yyyy") & strAffix
Loop
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top