Solved

Files in VB

Posted on 1998-12-30
11
149 Views
Last Modified: 2010-05-03
I need to erase duplicate lines in a file.
please write the code that does it.
0
Comment
Question by:amird
  • 5
  • 3
  • 2
  • +1
11 Comments
 

Author Comment

by:amird
ID: 1453199
Adjusted points to 100
0
 

Expert Comment

by:ChasDevlin
ID: 1453200
What is your file?   Is it a database or a text file?
0
 

Author Comment

by:amird
ID: 1453201
it's a text file

i need the function that search for duplicate lines and erase them

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453202
Are the duplicate lines after each other?

Sample:
xxx
xxx
yyy
zzz
zzz
xxx

So should the following file become a or b
a)
xxx
yyy
zzz
xxx
b)
xxx
yyy
zzz


0
 

Author Comment

by:amird
ID: 1453203
yes and no

the duplicate line scan be after each other or somewhere in the file
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453204
So option B is what you want? If not please give an example.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1453205
Private Sub RemoveDup(sFilePath As String)

    Dim iFile1 As Integer
    Dim iFile2 As Integer
    Dim iLine As Long
    Dim iline2 As Long
   
    Dim sString1 As String
    Dim sString2 As String
   
    Dim bDel(30000) As Boolean
   
    iFile1 = FreeFile
    Open sFilePath For Input As #iFile1
   
    While Not EOF(iFile1)
   
        Line Input #iFile1, sString1
        iLine = iLine + 1
   
        iFile2 = FreeFile
        Open sFilePath For Input As #iFile2
       
        iline2 = 0
        While Not EOF(iFile2)
       
            Line Input #iFile2, sString2
            iline2 = iline2 + 1
       
            If iline2 > iLine And sString1 = sString2 Then
           
                bDel(iline2) = True
               
            End If
           
        Wend
       
        Close iFile2
       
    Wend


    Close iFile1
   
    iFile1 = FreeFile
    Open sFilePath For Input As #iFile1
   
    iFile2 = FreeFile
   
    'Your text file is output here with no duplicates
    Open "Output" For Output As #iFile2
   
    iLine = 0
   
    While Not EOF(iFile1)
   
        Line Input #iFile1, sString1
        iLine = iLine + 1
        If Not bDel(iLine) Then
       
            Print #iFile2, sString1
           
        End If
       
    Wend
   
    Close #iFile1, #iFile2
   
   
End Sub


0
 
LVL 18

Expert Comment

by:deighton
ID: 1453206
sFilePath is the name and path of your file to process e.g.

"c:\data\file1.txt"


0
 

Author Comment

by:amird
ID: 1453207
the function doesnt work !!!!!!!!!!
0
 

Author Comment

by:amird
ID: 1453208
Sorry Thank you its working great
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1453209
ok, any more problems then just let me know.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now