CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    how to add text to the txt file.....

    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.....


  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: how to add text to the txt file.....

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured