PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

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

 
 
kimiraikkonen
Guest
Posts: n/a
 
      30th Oct 2007
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.

 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Oct 2007
"kimiraikkonen" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
 
 
 
kimiraikkonen
Guest
Posts: n/a
 
      31st Oct 2007
On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
(E-Mail Removed)> wrote:
> "kimiraikkonen" <(E-Mail Removed)> 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!

 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      31st Oct 2007
On Oct 31, 11:56 am, kimiraikkonen <(E-Mail Removed)> wrote:
> On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
>
>
> (E-Mail Removed)> wrote:
> > "kimiraikkonen" <(E-Mail Removed)> 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

 
Reply With Quote
 
Lloyd Sheen
Guest
Posts: n/a
 
      31st Oct 2007

"kimiraikkonen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> (E-Mail Removed)> wrote:
>> "kimiraikkonen" <(E-Mail Removed)> 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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      31st Oct 2007
"Lloyd Sheen" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
kimiraikkonen
Guest
Posts: n/a
 
      2nd Nov 2007
On Oct 31, 6:40 pm, "Lloyd Sheen" <(E-Mail Removed)> wrote:
> "kimiraikkonen" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > On Oct 30, 11:50 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> > (E-Mail Removed)> wrote:
> >> "kimiraikkonen" <(E-Mail Removed)> 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...

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning selected items in a listbox into another listbox DShikotra Webmaster / Programming 0 8th Jan 2008 03:25 PM
Listbox move multiple selected items to second listbox K B Microsoft ASP .NET 2 8th Jan 2007 12:16 PM
Moving listbox item from listbox to listbox Kevin Quigley Microsoft Dot NET 2 2nd Jun 2004 11:34 AM
How do I move all items in a listbox to another listbox kent Microsoft ASP .NET 1 3rd May 2004 01:17 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Microsoft Excel Programming 0 22nd Oct 2003 12:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:01 PM.