Solved

Visual Basic Text File Compare

Posted on 2011-09-27
16
299 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
  • 9
  • 7
16 Comments
 
LVL 51

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
 
LVL 51

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 51

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 51

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
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 51

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 51

Expert Comment

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

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 51

Accepted Solution

by:
HainKurt earned 500 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 51

Assisted Solution

by:HainKurt
HainKurt earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

14 Experts available now in Live!

Get 1:1 Help Now