Unanswered: Copy data from one file to another, with edits (was "Help!")
Hi, I have a text file and am trying to copy across all the data into a new text file. This sounds simple enough but I require some additional data to be added (three zero's). The file will look similar to as follows:
and the output to look something like:
Note : I only require the line's TCS to be updated with the "000". The example is very basic, just require some code to show how to do this.
If anybody can help, it will be greatly appreciated.
Option Compare Text
Function InFileToOutFile(InFile As String, OutFile As String)
Dim intInHandle As Integer
Dim intOutHandle As Integer
Dim strInLine As String
Dim strOutLine As String
intInHandle = FreeFile
Open InFile For Input As #intInHandle
intOutHandle = FreeFile
Open OutFile For Output As #intOutHandle
Do Until EOF(intInHandle)
Line Input #intInHandle, strInLine
If Left(strInLine, 4) = "TCS " Then
strOutLine = Left(strInLine, 11) & "000" & Mid(strInLine, 12)
strOutLine = strInLine
Print #intOutHandle, strOutLine
The incoming and outcoming files path and name are passed as parameters to the function. Ex:
InFileToOutFile("C:\Documents and Settings\SinnDHo\My documents\Access\dbforums\OriginalFile.txt", "C:\Documents and Settings\SinnDHo\My documents\Access\dbforums\ProcessedFile.txt")
You're assuming right: The Left function returns the nth left characters of a string whatever these characters can be, so a space counts as a character. More generally:
- The Left function returns a string containing a specified number of characters from the left side of a string.
- The Right function returns a string containing a specified number of characters from the right side of a string.
- The Mid function returns a string containing a specified number of characters from a string.
It's up to you to tell the function where the input file is and where to place the output file (they can be at different locations). If you do not specify a path, just a file name, then Access will search in it's default file location. To know where it is, open Access, in the Tools menu select Options then select the General tab. There you can find a text box specifying the default folder for the databases. This default folder is not only for databases it's also where Access will search for a file if you do not specify another folder.
- If you do not specify a folder Access will search for the input file and will write the output file in it's default folder. Ex: