Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 12th, 2003, 09:26 AM
Zinzi Zinzi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 Zinzi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Zinzi
Find lines duplicate in a text file

Hi at all..
i don't understand where i wrong. I would like fin a line duplicates in a text file. My code i wrong. Where? Thank's a lot.
Bye from Italy.
------------------------------ CODE START -------------------------------------
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s, filename, oldline, max
filename= "pippo.TXT"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filename)

Set tsmax = f.OpenAsTextStream(ForReading, Tristatefalse)
while not tsmax.AtEndOfStream
max=max+1
text=tsmax.ReadLine
wend
msgbox (max&"="&text)
tsmax.Close

Set tsorig = f.OpenAsTextStream(ForReading, Tristatefalse)
for i = 1 to max
orig=tsorig.ReadLine
start = tsorig.line
wscript.echo orig&start
Set tscomp = f.OpenAsTextStream(ForReading, TristateFalse)
for a = start to max
comp=tscomp.ReadLine
if orig=comp then
wscript.echo "Record :"& orig & " is duplicated "
end if
next
tscomp.Close
next
tsorig.Close
----------------------------------- CODE END -----------------------------

Last edited by Zinzi : September 12th, 2003 at 09:28 AM.

Reply With Quote
  #2  
Old September 23rd, 2003, 01:30 AM
Silian's Avatar
Silian Silian is offline
Gogga
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: A long, long time ago, in a galaxy, far, far away...
Posts: 34 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
The code is OK, except for one thing. Lets say that there are 8 lines in the text file. It reads the first line, and compares it with lines 1 to 8. It finds a match (bcs line 1 is the same as line 1). Then it reads line 2, and compares it with line 2 to 7 (finds a match, bcs line 2 is the same as line 2) Then it reads line 3, and compare it with line 3 to 6. etc.

The best way to solve this problem will be to tell it to start in the middle of the text file (at line 2, 3, etc). I am not sure if you can do this (maybe someone else can help out)

Otherwise (if you know that it's going to be a small file), you can read everything into an array when you get the number of lines
e.g. (untested)
Code:
dim oArr(100) as variant
while not tsmax.AtEndOfStream
max=max+1
text=tsmax.ReadLine
oArr(max) = text
wend
msgbox (max&"="&text)
tsmax.Close

Set tsorig = f.OpenAsTextStream(ForReading, Tristatefalse)
for i = 1 to max
orig=tsorig.ReadLine
start = tsorig.line
wscript.echo orig&start
for a = start + 1 to max
comp=oArr(a)
if orig=comp then 
wscript.echo "Record :"& orig & " is duplicated "
end if
next

or if you have can use access, you can use a temporary table to read everything into, and just select everything that appears twice.

Otherwise you can use basically the same code as you have, and just read the entire file, comparing only if a is larger than start
e.g. (untested)
Code:
for i = 1 to max
orig=tsorig.ReadLine
start = tsorig.line
wscript.echo orig&start
Set tscomp = f.OpenAsTextStream(ForReading, TristateFalse)
for a = 1 to max
comp=tscomp.ReadLine
if orig=comp and a > start then 
wscript.echo "Record :"& orig & " is duplicated "
end if
next


Hope this helps

Reply With Quote
  #3  
Old October 4th, 2003, 10:51 AM
asnavale asnavale is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: India
Posts: 5 asnavale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If the problem is due to comparing the line with itself( like line 1 with line 1 etc.,) as suggested by Silian, you can just skip this comparison. Put a line such as "if a=i then " and skip the comparison. This should solve the problem of self comparison.

- Anant Navale

Reply With Quote
  #4  
Old June 6th, 2005, 01:52 AM
Refresher Refresher is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 1 Refresher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 0
I know how to find duplicated files on your disks. This is the best prog for it: http://www.atory.com/Dupe_Checker_PRO/


IMHO!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Find lines duplicate in a text file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT