Deleting/Removing lines on Text File in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aadsaca
    New Member
    • Mar 2008
    • 17

    #1

    Deleting/Removing lines on Text File in VB

    Hi there,

    i just want to know the syntax on how
    to remove line on text file using
    vb...

    pls help me.

    tnx,
    arjel
    Last edited by jhardman; Apr 11 '08, 06:59 PM. Reason: moved to VB forum
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    This forum is for posting the questions related to asp . So if you want to post your question regarding VB you have to post it in the respected forum.

    The functionality that you require can be done using following lines of code :

    Code:
    Private Function DeleteLines(ByVal from_name As String, _
        ByVal to_name As String, ByVal target As String) As Long
    Dim strlen As Integer
    Dim from_file As Integer
    Dim to_file As Integer
    Dim one_line As String
    Dim deleted As Integer
    
        ' Open the input file.
        from_file = FreeFile
        Open from_name For Input As from_file
    
        ' Open the output file.
        to_file = FreeFile
        Open to_name For Output As to_file
    
        ' Copy the file skipping lines containing the
        ' target.
        deleted = 0
        Do While Not EOF(from_file)
            Line Input #from_file, one_line
            If InStr(one_line, target) = 0 Then
                Print #to_file, one_line
            Else
                deleted = deleted + 1
            End If
        Loop
    
        ' Close the files.
        Close from_file
        Close to_file
    
        DeleteLines = deleted
    End Function


    Originally posted by aadsaca
    Hi there,

    i just want to know the syntax on how
    to remove line on text file using
    vb...

    pls help me.

    tnx,
    arjel

    Comment

    Working...