TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

How to store/read listbox items in a text file line by line (with line break) ?

VB.NET

 
 
Thread Tools Display Modes
Unread 30-10-2007, 11:03 AM   #1
kimiraikkonen
Guest
 
Posts: n/a
How to store/read listbox items in a text file line by line (with line break) ?

Hi,
I want to save all the item content of a listbox line by line into a
simple text file then recall them when my project is opened.

For example listbox1 contains:

That - item1
Group -item2
Is -item3
Really -item4
Good -item5

And the text file must be 1:1 same then i have to load/syncronize
textfile to listbox when the project is opened.

Should i use streamreader/writer or is there another flexible class
that helps?

How can i do that?

Thanks.


Sponsored Links
 
Unread 30-10-2007, 10:04 PM   #2
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?

"kimiraikkonen" <kimiraikkonen85***********> schrieb:
> I want to save all the item content of a listbox line by line into a
> simple text file then recall them when my project is opened.
>
> For example listbox1 contains:
>
> That - item1
> Group -item2
> Is -item3
> Really -item4
> Good -item5
>
> And the text file must be 1:1 same then i have to load/syncronize
> textfile to listbox when the project is opened.
>
> Should i use streamreader/writer or is there another flexible class
> that helps?


'My.Computer.FileSystem.ReadAllText', 'My.Computer.FileSystem.WriteAllText',
'Split', 'Join'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Unread 31-10-2007, 04:06 PM   #3
kimiraikkonen
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?

On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.at> wrote:
> "kimiraikkonen" <kimiraikkone...***********> schrieb:
>
>
>
>
>
> > I want to save all the item content of a listbox line by line into a
> > simple text file then recall them when my project is opened.

>
> > For example listbox1 contains:

>
> > That - item1
> > Group -item2
> > Is -item3
> > Really -item4
> > Good -item5

>
> > And the text file must be 1:1 same then i have to load/syncronize
> > textfile to listbox when the project is opened.

>
> > Should i use streamreader/writer or is there another flexible class
> > that helps?

>
> 'My.Computer.FileSystem.ReadAllText', 'My.Computer.FileSystem.WriteAllText',
> 'Split', 'Join'.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -
>
> - Show quoted text -


Very thanks but i want to display them in a listbox line by line.

Dim reader As String
reader = My.Computer.FileSystem.ReadAllText("c:\test")
ListBox1.Items.Add(reader)

When i do that, ALL the text is displayed in the first line as
combined. But the original "test.txt" file has items line by
line(seperated with line break) as descibed in my previous message.

Thanks in advance!

 
Unread 31-10-2007, 05:06 PM   #4
rowe_newsgroups
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?

On Oct 31, 11:56 am, kimiraikkonen <kimiraikkone...***********> wrote:
> On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
>
>
> h...@gmx.at> wrote:
> > "kimiraikkonen" <kimiraikkone...***********> schrieb:

>
> > > I want to save all the item content of a listbox line by line into a
> > > simple text file then recall them when my project is opened.

>
> > > For example listbox1 contains:

>
> > > That - item1
> > > Group -item2
> > > Is -item3
> > > Really -item4
> > > Good -item5

>
> > > And the text file must be 1:1 same then i have to load/syncronize
> > > textfile to listbox when the project is opened.

>
> > > Should i use streamreader/writer or is there another flexible class
> > > that helps?

>
> > 'My.Computer.FileSystem.ReadAllText', 'My.Computer.FileSystem.WriteAllText',
> > 'Split', 'Join'.

>
> > --
> > M S Herfried K. Wagner
> > M V P <URL:http://dotnet.mvps.org/>
> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -

>
> > - Show quoted text -

>
> Very thanks but i want to display them in a listbox line by line.
>
> Dim reader As String
> reader = My.Computer.FileSystem.ReadAllText("c:\test")
> ListBox1.Items.Add(reader)
>
> When i do that, ALL the text is displayed in the first line as
> combined. But the original "test.txt" file has items line by
> line(seperated with line break) as descibed in my previous message.
>
> Thanks in advance!


Read the text file line by line (reader.ReadLine() I believe) in a
loop and add the items that way.

Thanks,

Seth Rowe

 
Unread 31-10-2007, 05:06 PM   #5
Lloyd Sheen
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?


"kimiraikkonen" <kimiraikkonen85***********> wrote in message
news:1193846166.924107.289210@y42g2000hsy.googlegr oups.com...
> On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> h...@gmx.at> wrote:
>> "kimiraikkonen" <kimiraikkone...***********> schrieb:
>>
>>
>>
>>
>>
>> > I want to save all the item content of a listbox line by line into a
>> > simple text file then recall them when my project is opened.

>>
>> > For example listbox1 contains:

>>
>> > That - item1
>> > Group -item2
>> > Is -item3
>> > Really -item4
>> > Good -item5

>>
>> > And the text file must be 1:1 same then i have to load/syncronize
>> > textfile to listbox when the project is opened.

>>
>> > Should i use streamreader/writer or is there another flexible class
>> > that helps?

>>
>> 'My.Computer.FileSystem.ReadAllText',
>> 'My.Computer.FileSystem.WriteAllText',
>> 'Split', 'Join'.
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -
>>
>> - Show quoted text -

>
> Very thanks but i want to display them in a listbox line by line.
>
> Dim reader As String
> reader = My.Computer.FileSystem.ReadAllText("c:\test")
> ListBox1.Items.Add(reader)
>
> When i do that, ALL the text is displayed in the first line as
> combined. But the original "test.txt" file has items line by
> line(seperated with line break) as descibed in my previous message.
>
> Thanks in advance!
>


Try this (just typed in so it may not be exact)

Dim reader as string
reader = My.Computer.FileSystem.ReadAllText("c:\test")

dim strs() as string
strs=split(reader,environment.newline) ' get an array of strings

then either

for each s as string in strs
listbox1.items.add(s)
next

or

listbox1.datasource = strs
listbox1.databind

Hope this helps
Lloyd Sheen



 
Unread 31-10-2007, 06:06 PM   #6
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?

"Lloyd Sheen" <a@b.c> schrieb:
> Dim reader as string
> reader = My.Computer.FileSystem.ReadAllText("c:\test")
>
> dim strs() as string
> strs=split(reader,environment.newline) ' get an array of strings
>
> then either
>
> for each s as string in strs
> listbox1.items.add(s)
> next


.... or 'ListBox1.Items.AddRange(Lines)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Unread 02-11-2007, 06:04 PM   #7
kimiraikkonen
Guest
 
Posts: n/a
Re: How to store/read listbox items in a text file line by line (with line break) ?

Sponsored Links
On Oct 31, 6:40 pm, "Lloyd Sheen" <a...@b.c> wrote:
> "kimiraikkonen" <kimiraikkone...***********> wrote in message
>
> news:1193846166.924107.289210@y42g2000hsy.googlegr oups.com...
>
>
>
> > On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> > h...@gmx.at> wrote:
> >> "kimiraikkonen" <kimiraikkone...***********> schrieb:

>
> >> > I want to save all the item content of a listbox line by line into a
> >> > simple text file then recall them when my project is opened.

>
> >> > For example listbox1 contains:

>
> >> > That - item1
> >> > Group -item2
> >> > Is -item3
> >> > Really -item4
> >> > Good -item5

>
> >> > And the text file must be 1:1 same then i have to load/syncronize
> >> > textfile to listbox when the project is opened.

>
> >> > Should i use streamreader/writer or is there another flexible class
> >> > that helps?

>
> >> 'My.Computer.FileSystem.ReadAllText',
> >> 'My.Computer.FileSystem.WriteAllText',
> >> 'Split', 'Join'.

>
> >> --
> >> M S Herfried K. Wagner
> >> M V P <URL:http://dotnet.mvps.org/>
> >> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -

>
> >> - Show quoted text -

>
> > Very thanks but i want to display them in a listbox line by line.

>
> > Dim reader As String
> > reader = My.Computer.FileSystem.ReadAllText("c:\test")
> > ListBox1.Items.Add(reader)

>
> > When i do that, ALL the text is displayed in the first line as
> > combined. But the original "test.txt" file has items line by
> > line(seperated with line break) as descibed in my previous message.

>
> > Thanks in advance!

>
> Try this (just typed in so it may not be exact)
>
> Dim reader as string
> reader = My.Computer.FileSystem.ReadAllText("c:\test")
>
> dim strs() as string
> strs=split(reader,environment.newline) ' get an array of strings
>
> then either
>
> for each s as string in strs
> listbox1.items.add(s)
> next
>
> or
>
> listbox1.datasource = strs
> listbox1.databind
>
> Hope this helps
> Lloyd Sheen


That Done IT!. Thanks but the last problem how to write into test.txt
with a "new line". I tried Mr. Wagner's suggestion
(me.computer.filesystem.writealltext) but i got that error:

Overload resolution failed because no accessible 'WriteAllText'
accepts this number.

I tried:

Dim writer As String
writer = My.Computer.FileSystem.WriteAllText("c:\bookmarks. txt")

How can i write / insert new text into "test.txt" as a NEWline?

Thanks...


Sponsored Links
 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 06:47 PM.


vBulletin, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2005-2016, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional