Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Visual Basic Text File Compare

Posted on 2011-09-27
16
Medium Priority
?
350 Views
Last Modified: 2012-05-12
Greetings,

 I would love some help with having my program check two text files and finding if a value is false to create a new text file with the false value. For the example I just put some values, but the real files have about 100 lines of different numbers. Just need to extract the values that are not true. Thanks

Eample:

Text1.text;

11111111
11111111
11111111
55525512

Text2.text

11111111
11111100
11111111
55525512

Text3.text
11111100
55525512
0
Comment
Question by:Jack_Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 59

Expert Comment

by:HainKurt
ID: 36713936
what does true false mean?
what does a value mean? a line?
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36713973
The two text files,

Text1.text, holds values that should be in the listview.
Text2.text, holds exported data from a listview item.
Text3.text, will receive data of the missing numbers.

My goal is to take Text3.text and have it imported to a listview to generate it's data of missing numbers. Hope this helps,

0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36713975
So,

Text1.text read and compare with Text2.text and if a value is not found to be a match, it will place it into Text3.text.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 59

Expert Comment

by:HainKurt
ID: 36714049
have a look at here

http://web.synametrics.com/plaintextfiles.htm

at the end you can write a query to get the difference which you can dump into another text file...
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 36714068
also look at here

http://users.drew.edu/skass/sql/TextDriver.htm

you create a linked server to mssql server, then use each file as table

select a.*
from test1 a left join test2 b on A.col1=B.col1 and A.col2=B.col2
where B.col1 is null

to get the difference
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36714082
Can VB do this with a file on the hard drive, i don't have access to SQL stuff, and this program will be used on my labtop that will not have internet access.
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 36714201
without sql, you can stil use ms text driver, create a user dsn, text driver, point to the folder
and use sql queries to select data from text files (each file will be a table)

instead of opening files, reading line by line, creating an array, then looping other, and checking each line in the array, and writing the difference to a text file is another method... but long way to go...
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36714216
Let me ask this, as I can get it to work. Found this using google and trying / trying harder lol.

The only part I can't seem to figure out is the part where if it's not the same to put the items from the array that are not the same into foundskus.items.add("")


 Dim LineOfText1 As String, LineOfText2 As String
        Dim i As Integer, c As Integer
        Dim arryTextFile1() As String, arryTextFile2() As String

        LineOfText1 = TextBox2.Text
        arryTextFile1 = LineOfText1.Split(",")

        For i = 0 To UBound(arryTextFile1)
            'MsgBox(arryTextFile1(i))
        Next i

        LineOfText2 = TextBox3.Text
        arryTextFile2 = LineOfText2.Split(",")

        For c = 0 To UBound(arryTextFile2)
            'MsgBox(arryTextFile2(c))
        Next c

        If arryTextFile1.Equals(arryTextFile2) Then
            'MessageBox.Show("files are the same")
        Else
            foundskus.Items.Add("Missing Items")
        End If

Open in new window

0
 
LVL 59

Expert Comment

by:HainKurt
ID: 36714231
this one does not read from files
a string delimited with ","
foundskus is an object (maybe a listbox, combo, table etc)
it does not write to file...

if you go this way, steps are:

1 open input file 1
2 reading line by line,
3 creating an array, put each line into array
4 close file
5 then open other file , write a new file, output
6 looping other,
7 checking each line in the array
8 writing the difference to a output file
9 close all files
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36714272
could you help me with that please, spent all night trying to figure it out.
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 36717033
is your input files have same number of lines? and do we match same lines?
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 36717108
something like these
Dim fn1 As String = "C:\Users\Owner\Documents\test1.txt"
Dim fn2 As String = "C:\Users\Owner\Documents\test2.txt"
Dim fn3 As String = "C:\Users\Owner\Documents\test3.txt"

Dim Line1, Line2 As String

Dim objReader1 As New System.IO.StreamReader(fn1)
Dim objReader2 As New System.IO.StreamReader(fn2)
Dim objWriter As New System.IO.StreamWriter(fn3)

Do While (objReader1.Peek() <> -1) and (objReader2.Peek() <> -1)
  Line1 = objReader1.ReadLine()
  Line2 = objReader2.ReadLine()
  if (Line1 <> Line2) objWriter.Write(Line1)
Loop

objWriter.Close()

Open in new window

0
 
LVL 59

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 36717114
have a look at these sources...

Reading a Text File Line by Line : http://homeandlearn.co.uk/NET/nets8p3.html
How to Write to a Text File in VB .NET : http://homeandlearn.co.uk/NET/nets8p4.html
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36796521
Where would I put the End If, after the IF statement.
0
 
LVL 59

Assisted Solution

by:HainKurt
HainKurt earned 2000 total points
ID: 36815667
i guess no need for end if (also I forgot "Then")

it is one line one statement but if you need

if (Line1 <> Line2) objWriter.Write(Line1)
-->

if (Line1 <> Line2) Then objWriter.Write(Line1)

or this one if you have multiple statements in if...then

if (Line1 <> Line2) Then
  objWriter.Write(Line1)
End if
0
 
LVL 1

Author Closing Comment

by:Jack_Jones
ID: 36816316
Worked like a charm, thank you so much!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

715 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