VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,807 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,665 people online right now. Registration is fast and FREE... Join Now!




compare between 2 txt files and save it in new txt . P

 

compare between 2 txt files and save it in new txt . P

meloco

2 Apr, 2009 - 12:02 AM
Post #1

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 4

iam newbie to this, hope your help

I have many txt files, and i have to select any txt file to search and compare match fields with file: CompareText.txt. My text file format:


20090227#2#B010110100#3787.562904#
20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#

20090227#2#B010110211#14073.69#
......


CompareText.txt

B010110200
B010110400
B010110413
B010110411
B010110213

, I can get the same result
(depend on the third column to compare), then i must save this result to new txt file . Examples, this result from 2 txt files:

20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#

help Pls urgent...thanks in advance
Best Regards

This post has been edited by meloco: 2 Apr, 2009 - 12:29 AM

User is offlineProfile CardPM
+Quote Post


AdamSpeight2008

RE: Compare Between 2 Txt Files And Save It In New Txt . P

2 Apr, 2009 - 01:01 AM
Post #2

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,730



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
The following tutorial could of some use to you.
Tutorial:TextFieldParser Tutorial
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Compare Between 2 Txt Files And Save It In New Txt . P

2 Apr, 2009 - 07:10 AM
Post #3

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,919



Thanked: 517 times
Dream Kudos: 11525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

meloco

RE: Compare Between 2 Txt Files And Save It In New Txt . P

6 Apr, 2009 - 07:00 PM
Post #4

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 4

ok, thanks u all,
I find the solution to solve, that is: I will import all content with # delimited into a table called Import in Access and after that i will export this table into a datagridview and then i will export it into other text file, but i get errors when i import txt file into Access. This is my code:

Name of text file: BC0902281.A0131700101 -> i get id from a part of txt name : 01317001.
Content of txt file:
BG#01317001#D01#
20090228#5#D0101#1274193999025#
20090228#5#D0102#1227149540626#
EN#01317001#D01#2#
BG#01317001#A0101#

these lines contain EN and BG must not be inserted into acess

CODE

Private Function sqlInsert(ByVal id As String, ByVal name As String, ByVal info As String, ByVal qual As double, ByVal datetime As String) As String
        Dim sql As String
        sql = ""
        sql = sql & "INSERT INTO IMPORT (id, name, info, qual, datetime) VALUES("
        sql = sql & "'" & id & "' "
        sql = sql & ",'" & name & "' "
        sql = sql & ",'" & info & "' "
        sql = sql & ",'" & qual & "' "
        sql = sql & ",'" & datetime & "' "
        sql = sql & ")"
        sqlInsert = sql
    End Function

    Private Sub btnFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileName.Click
        Dim Conn As New System.Data.OleDb.OleDbConnection
        Dim Comm As New System.Data.OleDb.OleDbCommand
        Dim i As Integer
        Dim arrLine As String()
        Dim arrLines As String()
        Dim strFileName As String
        Dim sql As String
        Dim rsl As DialogResult

        Conn.ConnectionString = getConnectionString_MSACCESS("\\server\Data\test\SELECT_FILES\db1.mdb", "", "")
        Conn.Open()
        Comm.Connection = Conn

        With Me.OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .Multiselect = True
            .Title = "Text files Browser"
            rsl = .ShowDialog()
            If rsl = Windows.Forms.DialogResult.OK Then
                For Each s As String In OpenFileDialog1.FileNames
                    Dim fi = OpenFileDialog1.FileName
                    strFileName = IO.Path.GetFileName(s)
                    txtText.Text = fi
                    MessageBox.Show(strFileName)

                    arrLines = System.IO.File.ReadAllLines(strFileName)


                    Dim id, name, info, qual, datetime As String
                    id = ""
                    datetime = ""

                    If arrLines.Length > 0 Then
                        datetime = arrLines(0).ToString()
                        arrLine = arrLines(0).ToString().Split("#")
                        datetime =  arrLine(1).Substring(4, arrLine(1).Length - 4)+ "/" +  arrLine(1).Substring(2, 2) + "/" + arrLine(1).Substring(0, 2)
                       id = strFileName.Substring(strFileName.Length - 14, 8)
                    End If
                    For i = 1 To arrLines.Length - 1
                        arrLine = arrLines(i).ToString().Split("#")
                        If arrLine(0) <> "EN" And arrLine.Length = 4 Then
                            name = arrLine(0)
                            info = arrLine(1)
                            qual = arrLine(2)

                            sql = sqlInsert(id, name, info, qual, datetime )           Comm.Connection = Conn
                            Comm.CommandText = sql
                            Comm.ExecuteNonQuery()

                        End If
                    Next
                Next
                MessageBox.Show("Sucessfully!")
            End If
        End With
    End Sub


plz help me. thanks

This post has been edited by meloco: 6 Apr, 2009 - 07:03 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Compare Between 2 Txt Files And Save It In New Txt . P

6 Apr, 2009 - 08:31 PM
Post #5

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,919



Thanked: 517 times
Dream Kudos: 11525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
A note, in VB.NET you no longer need to add to a string like str = str & "SomeValue, you can use the C++ syntax like str &= "SomeValue" (makes less typing for you)

CODE

Private Function sqlInsert(ByVal id As String, ByVal name As String, ByVal info As String, ByVal qual As double, ByVal datetime As String) As String
        Dim sql As String
        sql = ""
        sql &= "INSERT INTO IMPORT (id, name, info, qual, datetime) VALUES("
        sql &= "'" & id & "' "
        sql &= ",'" & name & "' "
        sql &= ",'" & info & "' "
        sql &= ",'" & qual & "' "
        sql &= ",'" & datetime & "' "
        sql &= ")"
        
        Return sql
End Function


User is offlineProfile CardPM
+Quote Post

meloco

RE: Compare Between 2 Txt Files And Save It In New Txt . P

6 Apr, 2009 - 10:47 PM
Post #6

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 4

but my problem is my txt contains many "BG" and "EN" lines, its content:

BG#01505001#B0101#
20090327#2#B010110100#0#
20090327#2#B010110200#171391.384433#
20090327#2#B010110213#1046589.24#
20090327#2#B010110211#6973.69#
20090327#2#B01012011111#1581.58#
EN#01505001#B0101#43#
BG#01505001#A07#
20090227#2#A07910100#507135679694#
20090227#2#A07910113#8863883.56#


.....


I must remove BG and EN line and there are 2 datetime fields in the above examples: 20090327 -> 27/03/2009; 20090227 ->27/02/2009; name field is insert in access is: 2; info: is the third array...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 09:48PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month