Listbox contents to .txt file

Chris-Ramsey

New member
Joined
Mar 28, 2008
Messages
4
Programming Experience
Beginner
Hi, I am new so if this is the wrong section I am sorry. :confused:

Bascially, we have to create a till application for a Pizza Restaurant, for my Level 3 BTEC National Diploma course, in VB.NET. I am using VB.NET 2005 Express edition (Free) at home and Visual Studio 2005 at college.

I am using a ListBox as the order form. It adds items as you along selecting drinks, food etc. I need to be able to get all this information into a text file to demonstrate how the order could be sent to the kitchen over a network. Only trouble is, I have no idea how to save all the list box items to a .txt file. I have searched the net but cant find much. I want to be able to save each line individually as well.

Another problem with the listbox (while i'm here). is there anyway I can make it multiline. I've got a textbox where the user can enter special orders and add this to the listbox. The only trouble is, all the text gets added as one line. i want to be able to get the text to go to the next line if it reaches the end.

Thanks in advance if anyone can help. Brilliant Forum btw. :D:D
 
Ok, I have worked out how to add he contents of a ListBox to a txt file. I will put the code at the bottom of this reply in case anyone else is looking for the same answer as me.

Would still appreciate any help with this multiline ListBox though. I have heard it is complicated and I have no idea.

code for adding contents of listbox to txt file:

FileOpen(FileNumber, "C:\PizzaShed.txt", OpenMode.Output)
For Each Item As Object In ListBox1.Items
PrintLine(FileNumber, Item.ToString)
Next
FileClose(FileNumber)
 
That's basically it for a ListBox. I've used ListViews (in detail view) to do the same thing for assignments before.
 
Here is some more code to save multi-column List View Items to a txt file:

VB.NET:
Expand Collapse Copy
Dim outputstream As StreamWriter = File.CreateText("C:\Order.txt")
Dim s As Short
Dim newstr(::number of columns::) As String
Dim I As Integer
Dim column1 As String
Dim column As String
Dim ItemCount As String
ItemCount = ListView1.Items.Count
For I = 0 To ItemCount - 1
  For s = 0 To ::number of columns::
  newstr(s) = ListView1.Items.Item(I).SubItems(s).Text
  Next
  column1 = newstr(0)
  column2 = newstr(1)
  outputstream.WriteLine(column1 & "|" & column2)
Next I
outputstream.Close()

Let me know if this helps :)
 
Back
Top