Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to delete line in text file

    in the first i like this web site so much


    about my problem i need help in how i can delete line in text file

    i have code in chatting module this code save the chatting in text file so i need help in how i can deletle the first line when the lines comes 500 lines
    i need idea how i can make this array
    this array made to delete the first line when the lines come to the max (200 line)

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    try:

    dim filesys, readfile, contents, arrContents
    const maxlen = 500
    set filesys = CreateObject("Scripting.FileSystemObject")
    set readfile = filesys.OpenTextFile("c:\somefile.txt", 1, false)
    contents = readfile.ReadAll
    readfile.close

    arrContents = split(contents,VbCrLf)
    if ubound(arrContents) = maxlen - 1 then
    'already reached the max line number
    else
    'not yet reached the max line number
    end if
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for your help
    but how i can delete the first line in the text file

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    set the first item in the array empty

    arrContents = split(contents, VbCrLf)
    if ubound(arrContents) = maxlen - 1 then

    'already reached the max line number
    arrContents(0)=""
    contents = Join(arrContents, VbCrLf) 'convert back to string
    'do other stuff

    else

    'not yet reached the max line number

    end if
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    does't work i can tell u my code may be i have problem in this code

    Set fileObject = Server.CreateObject("Scripting.FileSystemObject")
    textFile = c:\somefile.txt

    If Not fileObject.FileExists(textfile) Then
    Set inStream = fileObject.OpenTextFile(textFile,8,True,FALSE)
    nStream.WriteLine " "
    End If

    Set inStream = fileObject.OpenTextFile(textFile,1,TRUE,FALSE)
    contents = inStream.ReadAll
    Set inStream = Nothing

    const maxlen = 200
    arrContents = split(contents, VbCrLf)
    if ubound(arrContents) = maxlen - 1 then

    'already reached the max line number
    arrContents(0)=""
    contents = Join(arrContents, VbCrLf) 'convert back to string
    'do other stuff

    else

    'not yet reached the max line number

    end if


    If IsNull(Session("Enter")) Or Session("Enter") = True Then
    Session("Enter") = False
    End If

    If Request.Form("Add") = "TRUE" Then
    file = file & "<FONT SIZE=2 Color=#000000 FACE='Verdana,Arial'><b>" & name & "</b></FONT><FONT FACE='Vedana,Arial' Color=#0000FF SIZE=1 >("& date &"-"& timeaa &" GMT):</FONT>" & Request("Msg") & "<br>"


    Set outStream = fileObject.CreateTextFile(textFile,True)
    outStream.WriteLine(contents)
    Set outStream = Nothing

    End If

    Response.Write "<font color=#000000>" & contents & ""

    i have comment this code not delete the first line i need delete the first line form the text file

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    you're not closing the inStream and outStream objects.

    If Not fileObject.FileExists(textfile) Then
    Set inStream = fileObject.OpenTextFile(textFile,8,True,FALSE)
    inStream.WriteLine " "
    inStream.Close
    End If

    Set outStream = fileObject.CreateTextFile(textFile,True)
    outStream.WriteLine(contents)
    outStream.Close
    Set outStream = Nothing
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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