473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help needed, Removing duplicate lines in text file

Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ☺

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy

Jun 19 '06 #1
10 6736
Hello, Andy,

There are different ways to approach this. The "best" way may depend on
how (and with what type of objects) you are now loading your combo-box.

In an earlier case I have done something similar by creating a class
that suppressed duplicate entries and used that to load the list.

But in your case it might be better simply to examine each entry in
History.txt before you place it into your ComboBox list to see if it
already exists.

If you can give some details (e.g. a code snippet) showing how you are
currently loading your list, you might get a better answer.

Cheers,
Randy
Perhaps you can best filter the

Backwards wrote:
Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ☺

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy

Jun 19 '06 #2
Hi in addition to Randy,

If it's possible I would prefer to save the address history in a table then
it's very easy to do select distinct ....
But you can also do a select on a text file, for example:
Assuming this is your text file:
addresses.txt

ADDRESS
"192.168.1.1"
"192.168.1.1"
"192.168.1.3"
"192.168.1.5"
"192.168.1.5"

ADDRESS needs to be included, it's the columnheader, you can also do it
without a columnheader but my sample uses it.

Dim myCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & Application.StartupPath & "\" & ";Extended
Properties=""text;HDR=Yes;FMT=Delimited""")
Dim myAdapter As New OleDbDataAdapter("Select distinct address from
addresses.txt", myCon)
Dim myDataset As New DataSet

myCon.Open()
myAdapter.Fill(myDataset)
myCon.Close()

For i As Integer = 0 To myDataset.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(CStr(myDataset.Tables(0).Rows( i).Item(0)))
Next
Hope this helps

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"R. MacDonald" <sc****@NO-SP-AMcips.ca> schreef in bericht
news:44***********************@news.wanadoo.nl...
Hello, Andy,

There are different ways to approach this. The "best" way may depend on
how (and with what type of objects) you are now loading your combo-box.

In an earlier case I have done something similar by creating a class
that suppressed duplicate entries and used that to load the list.

But in your case it might be better simply to examine each entry in
History.txt before you place it into your ComboBox list to see if it
already exists.

If you can give some details (e.g. a code snippet) showing how you are
currently loading your list, you might get a better answer.

Cheers,
Randy
Perhaps you can best filter the

Backwards wrote:
Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ?

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy

Jun 19 '06 #3
This is my code on form load that pulls the info from the history.txt

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Me.ComboBox1.Items.Clear()

If Not File.Exists(Application.UserAppDataPath +
"\History.txt") Then
MessageBox.Show("History file was not found, no histroy
will be showen", Application.ProductName, MessageBoxButtons.OK,
MessageBoxIcon.Information)
'Return
End If
Using sr As StreamReader =
File.OpenText(Application.UserAppDataPath + "\History.txt")
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
'MessageBox.Show(input)
Me.ComboBox1.Items.Add(input)
input = sr.ReadLine()
End While
'MessageBox.Show("The end of the stream has been
reached.")
sr.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error"

Jun 19 '06 #4
Randy,

From what I understood (and I thought I did) in your message is the solution
for you to use the SortedList instead between the txt.file.

This can contains only one key.

http://msdn.microsoft.com/library/de...classtopic.asp
If it is about multi-user practise than you need of course a whatever
database

I hope this helps,

Cor

"Backwards" <An****@technicaltraining.co.nz> schreef in bericht
news:11**********************@f6g2000cwb.googlegro ups.com...
Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ?

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy
Jun 19 '06 #5
Hello, Andy,

Can you replace the ComboBox1.Items.Add line with:

If (Not ComboBox1.Items.Contains(input)) Then
ComboBox1.Items.Add(input)
End If

(Though, you may need to be a little more elaborate if you want your
comparison to be case insensitive.)

Cheers,
Randy
Backwards wrote:
This is my code on form load that pulls the info from the history.txt

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Me.ComboBox1.Items.Clear()

If Not File.Exists(Application.UserAppDataPath +
"\History.txt") Then
MessageBox.Show("History file was not found, no histroy
will be showen", Application.ProductName, MessageBoxButtons.OK,
MessageBoxIcon.Information)
'Return
End If
Using sr As StreamReader =
File.OpenText(Application.UserAppDataPath + "\History.txt")
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
'MessageBox.Show(input)
Me.ComboBox1.Items.Add(input)
input = sr.ReadLine()
End While
'MessageBox.Show("The end of the stream has been
reached.")
sr.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error"

Jun 19 '06 #6
Hello, Cor,

Your guess is perfect. My class inherited SortedList. But I suspect
that this is more involved than what the OP requires.

(Oops, I seem to have posted my suggestion in the wrong sub-thread.)

Groetjes,
Randy
Cor Ligthert [MVP] wrote:
Randy,

From what I understood (and I thought I did) in your message is the solution
for you to use the SortedList instead between the txt.file.

This can contains only one key.

http://msdn.microsoft.com/library/de...classtopic.asp
If it is about multi-user practise than you need of course a whatever
database

I hope this helps,

Cor

"Backwards" <An****@technicaltraining.co.nz> schreef in bericht
news:11**********************@f6g2000cwb.googlegro ups.com...
Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ?

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy

Jun 19 '06 #7
Hello, Andy,

Can you replace the ComboBox1.Items.Add line with:

If (Not ComboBox1.Items.Contains(input)) Then
ComboBox1.Items.Add(input)
End If

(Though, you may need to be a little more elaborate if you want your
comparison to be case insensitive.)

Cheers,
Randy

Backwards wrote:
This is my code on form load that pulls the info from the history.txt

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Me.ComboBox1.Items.Clear()

If Not File.Exists(Application.UserAppDataPath +
"\History.txt") Then
MessageBox.Show("History file was not found, no histroy
will be showen", Application.ProductName, MessageBoxButtons.OK,
MessageBoxIcon.Information)
'Return
End If
Using sr As StreamReader =
File.OpenText(Application.UserAppDataPath + "\History.txt")
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
'MessageBox.Show(input)
Me.ComboBox1.Items.Add(input)
input = sr.ReadLine()
End While
'MessageBox.Show("The end of the stream has been
reached.")
sr.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error"

Jun 19 '06 #8
Randy, I see I wrote a R to much it had to be Andy.

:-)

Cor

"R. MacDonald" <sc****@NO-SP-AMcips.ca> schreef in bericht
news:44***********************@news.wanadoo.nl...
Hello, Cor,

Your guess is perfect. My class inherited SortedList. But I suspect that
this is more involved than what the OP requires.

(Oops, I seem to have posted my suggestion in the wrong sub-thread.)

Groetjes,
Randy
Cor Ligthert [MVP] wrote:
Randy,

From what I understood (and I thought I did) in your message is the
solution for you to use the SortedList instead between the txt.file.

This can contains only one key.

http://msdn.microsoft.com/library/de...classtopic.asp
If it is about multi-user practise than you need of course a whatever
database

I hope this helps,

Cor

"Backwards" <An****@technicaltraining.co.nz> schreef in bericht
news:11**********************@f6g2000cwb.googlegro ups.com...
Hello all,

I'll start by explaining what my app does so not to confuss you when i
ask my question. ?

I have a VB.Net 2.0 app that starts a process (process.start ...) and
passes a prameter through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt

My.Computer.FileSystem.WriteAllText(Application.Us erAppDataPath +
"\History.txt", Me.ComboBox1.Text + vbCrLf, True)

When the application is restarted (closed and opend) its clears the
combo box items (me.combobox1.items.clear()) and then imports them from
the above history.txt file.

However the problem i have is with common address's that are used. (ie
192.168.0.1) these show in the list 4 or 5 times as they have been
typed into the combo box 4 -5 times by the user.

Is there anyway on form1.load to read this text file and remove any
line that has the same address?

If you need any more info please let me know.
All and any help would be nice.

Regards,

Andy


Jun 19 '06 #9
Hello Randy,

This seems to have worked just how i wanted it to. Place 10 of the same
address's in the history.txt file but only one showed up in the combo
box.

Thanks to all for input on this and i hope it helps others in the
future.

Andy


R. MacDonald wrote:
Hello, Andy,

Can you replace the ComboBox1.Items.Add line with:

If (Not ComboBox1.Items.Contains(input)) Then
ComboBox1.Items.Add(input)
End If

(Though, you may need to be a little more elaborate if you want your
comparison to be case insensitive.)

Cheers,
Randy

Backwards wrote:
This is my code on form load that pulls the info from the history.txt

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Me.ComboBox1.Items.Clear()

If Not File.Exists(Application.UserAppDataPath +
"\History.txt") Then
MessageBox.Show("History file was not found, no histroy
will be showen", Application.ProductName, MessageBoxButtons.OK,
MessageBoxIcon.Information)
'Return
End If
Using sr As StreamReader =
File.OpenText(Application.UserAppDataPath + "\History.txt")
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
'MessageBox.Show(input)
Me.ComboBox1.Items.Add(input)
input = sr.ReadLine()
End While
'MessageBox.Show("The end of the stream has been
reached.")
sr.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error"


Jun 19 '06 #10
I was half asleep before and did the same thing said Randy when i
wanted to say thanks to R. MacDonald.

And of course to everyone else

regards,
Andy

Jun 19 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
41
by: Seth | last post by:
I am in need of source code for the Aho Corasick algorithm. I have tried searching the web but can't seem to find any code. Is there a good site for c code I can search? Thanks in advance.
3
by: Dave | last post by:
I want to create a thread object to find any duplicate characters within a string and get rid of all the duplicate characters within the string, such as str="abbecdffet". After the thread object...
5
by: nuffnough | last post by:
This is python 2.4.3 on WinXP under PythonWin. I have a config file with many blank lines and many other lines that I don't need. read the file in, splitlines to make a list, then run a loop...
5
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
118
by: Chuck Cheeze | last post by:
This might be in the wrong group, but... Here is an example of my data: entry_id cat_id 1 20 2 25 3 30 4 25 5 35
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.