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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending data into the textfile in a new line

Status
Not open for further replies.

jessiejane

Programmer
Oct 29, 2009
32
US
Hi,

I have a temp file (temp.txt) and purge file (purge.txt)

I compare the data in the temp file against the purge file and if the record exists in both the files I do not add the data, if the record in the temp file does not exist in the purge file, I append the data to the purge file.

When I append the data it adds in the same line instead of n
ew line and then adds other records to the new line

Any help is really appreciated.

****************
temp.txt
-----------------
John-02/03/2010
Mary-04/15/2010
Richard-05/17/2010
*****************

*****************
Purge.txt
-----------------
Mary-02/12/2010

*****************
________________________________
Mary-02/12/2010John-02/03/2010
Richard-05/17/2010
________________________________
The output looks like above but I need the records to have in a seperate line like the below one
________________________________
Mary-02/12/2010
John-02/03/2010
Richard-05/17/2010
________________________________

Code:

For int i = 1 to 3
strUserFound = False
For j = 1 to 1
if ucase(Mid(arrTemp(i - 1),1,(instr(1,arrTemp(i-1),"-")-1)))= ucase(Mid(arrPurge(j - 1),1,(instr(1,arrPurge(j-1),"-")-1))) then

strUserFound = True
Exit for
end if
Next
If strUserFound <> True then
EventLog ucase(Mid(arrTemp(i - 1),1,(instr(1,arrTemp(i-1),"-")-1))) & "-" & Date, strPurgeFile

End If
Next

Sub EventLog(ByVal strLogValues, ByVal strFile)
Dim objTextFile, objCreateFile
if objFSO.FileExists(strDirectory & strFile) <> True then
Set objCreateFile = objFSO.CreateTextFile(strDirectory & strLogFile, True)
objCreateFile.Close
End if
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, strAppendingValue, True)
objTextFile.Writeline(strLogValues)
objTextFile.Close
End Sub

 
You may try to replace this:
objTextFile.Writeline(strLogValues)
with this:
objTextFile.Write vbCrLf & strLogValues

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It worked but I got another issue when I replace the writeline.

When the purge file is empty, it adds all the records in the Temp file at that point it inserts an blank line on the purge file.

Any help is greatly appreciated.
________________________________

Mary-02/12/2010
John-02/03/2010
Richard-05/17/2010
________________________________

Code:
Do Until objTempFile.AtEndOfStream
redim Preserve arrTemp(intArrTemp)
arrTemp(intArrTemp) = objTempFile.ReadLine
strUserValue = ucase(Mid(arrTemp(intArrTemp),1, (instr(1,arrTemp(intArrTemp), "-")-1)))
EventLog strUserValue & "-" & Date, strPurgeFile
intArrTemp = intArrTemp + 1
Loop
objTempFile.Close
End If

Sub EventLog(ByVal strLogValues, ByVal strFile)
Dim objTextFile, objCreateFile
if objFSO.FileExists(strDirectory & strFile) <> True then
Set objCreateFile = objFSO.CreateTextFile(strDirectory & strLogFile, True)
objCreateFile.Close
End if

If strFile = strPurgeFile then
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, strAppendingValue, True)
MsgBox "Purge Values" & strLogValues
ObjTextFile.Write vbCrLf& strLogValues
End If
ObjTextFile.Close

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top