Click to See Complete Forum and Search --> : how to add text to the txt file.....


AndyK
October 20th, 1999, 06:35 PM
I need to add a line to the .txt file, but i need it to add after specific line, not first line or last line of text...So how can i search for that line and tell vb to add new line after specific line....not replace the specific, add.....

Ravi Kiran
October 20th, 1999, 09:37 PM
Look for new-line characters - vbCrlf
Count that many, say N, and break the text after that point by copying into another text buffer with Mid$ -(May have some touble, if that buffer is too big!)


i = 0:j = 1
do
breakat = Instr(j, tmpbuf,vbcrlf)
if breakat = 0 then
' no more new lines!!. error
exit do
else
j = j + breakat + len(vbcrlf) '
i = i + 1
end if
if i = n then
tmpbuf1 = mid$(tmpbuf,j + len(vbcrlf)
tmpbuf = left$(tmpbuf,j-1)
end if
loop
' add some code here to catch the error, if we
' could not find 'n' no.of line breaks

' assuming no error..
tmpbuf = tmpbuf & vbcrlf & new_string & vbcrlf & tmpbuf1





RK