Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > reading 5txtfilels,checking for duplicate and saving the duplicate in 1file and the


Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2004, 03:06 AM
mmasedikwe mmasedikwe is offline
Newcomer
 
Join Date: Jul 2004
Posts: 3
Red face reading 5txtfilels,checking for duplicate and saving the duplicate in 1file and the


please help

I'm still new in vb and I'm trying to read 5 txtfiles and checking for duplicate records then write the duplicate records in their file(outputfile) and then write the rest of the records into an output file.

duplicates in their output file
non duplicate in their output file
Reply With Quote
  #2  
Old 08-25-2004, 03:24 AM
an5w3r's Avatar
an5w3r an5w3r is offline
Senior Contributor
 
Join Date: Jan 2004
Location: Romania
Posts: 1,342
Default

You should first check this link for learning more about writing/reading from files.

So you should do something like this (supposing that each record in on a different line):
Code:
Dim strtextfile As String Dim strtextfile1 As String Dim strtextfile2 As String Dim strtextfile3 As String Dim lines() as String dim logic as boolean dim duplicate as string dim nonduplicate as string hfile = FreeFile Open "file1.txt" For Input As #hfile strtextfile1 = Input$(LOF(hfile), hfile) Close #hfile hfile = FreeFile Open "file2.txt" For Input As #hfile strtextfile2 = Input$(LOF(hfile), hfile) Close #hfile hfile = FreeFile Open "file3.txt" For Input As #hfile strtextfile3 = Input$(LOF(hfile), hfile) Close #hfile ' and so on until 5 ' after than concatenate them into a single file strtextfile=strtextfile1 & vbcrlf & strtextfile2 & vbcrlf & strtextfile3 ' after that split the string by the vbcrlf character (newline) lines=split(strtextfile,vbcrlf) ' then check each value to see if it's a duplicate for i=0 to ubound(lines)-1 logic=true for j=i+1 to ubound(lines) if lines(i)=lines(j) and (lines(i) <>"" or lines(j) <> "") then duplicate=duplicate & vbcrlf & lines(i) lines(j)="" logic=false end if next j ' if no duplicate found then add that line to nonduplicates if logic then nonduplicate=nonduplicate & vbcrlf & lines(i) end if next i ' then write the duplicate to the duplicate.txt and nonduplicate to nondup.txt or wherever you want

I've written this code now for giving you a general idea on how you should think this problem... don't copy-paste it because it won't work
__________________
Fully customizable and easy to use .NET WPF charting library http://www.SoftwareGFX.com

Last edited by an5w3r; 08-25-2004 at 03:40 AM.
Reply With Quote
  #3  
Old 08-25-2004, 06:48 AM
mmasedikwe mmasedikwe is offline
Newcomer
 
Join Date: Jul 2004
Posts: 3
Default

thanks for help,I realy appreciate it .We got the program working now but we only have one problem.We don't want the program to clean the duplicate out,but to copy the duplicate into a duplicate output file.(leaving the origional record in the file and just copying it) the duplicate must also be written into the output file with the other records)

Please help
Reply With Quote
  #4  
Old 08-25-2004, 08:38 AM
an5w3r's Avatar
an5w3r an5w3r is offline
Senior Contributor
 
Join Date: Jan 2004
Location: Romania
Posts: 1,342
Default

You can open the file for append if you want to add informations after the last line. Check
gavin0's tutorial on writing and reading from the Tut's Corner.
__________________
Fully customizable and easy to use .NET WPF charting library http://www.SoftwareGFX.com
Reply With Quote
  #5  
Old 08-25-2004, 09:27 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->