[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Visual Basic Text File Compare

Posted on 2011-09-27
16
Medium Priority
?
365 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 61

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 61

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 61

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 61

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 61

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 61

Expert Comment

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

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 61

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 61

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

591 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