Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Go Back  Xtreme Visual Basic Talk > > > Saving a Listbox orr adding a list box to a text file


Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2014, 12:39 PM
Inlee Inlee is offline
Newcomer
 
Join Date: Dec 2014
Posts: 1
Default Saving a Listbox orr adding a list box to a text file


Ok, I have been struggling with this for about a month now, have searched for the help could not find it. Maybe I am just not understanding it. I will post here what I have and what I am trying to accomplish and see if anyone has any suggestions on a direction to try.

I have a Listbox that takes all of the information from several textboxs and combines it into said listbox. From there I need to save that listbox into a text file and/or have it all transfer into a textbox so I can save it. I have my textbox set to save, works like it is supposed to so no problem there, just a matter of, for lack of better words, making the listbox copy itself to the textbox so I can save it.

listbox1 = lbxLoad
textbox1.text = txtLoad.Text

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInfo.Click
lbxLoad.Items.Add("[Load Information]")
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add(" ")
lbxLoad.Items.Add("Load Number: " & vbTab & txtLoadNumber.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add(" ")
lbxLoad.Items.Add("[Pickup Information] ")
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Pickup Date: " & vbTab & DateTimePicker1.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Shipper: " & vbTab & vbTab & txtShipper.Text)
lbxLoad.Items.Add("Address: " & vbTab & vbTab & txtShipperAddress.Text)
lbxLoad.Items.Add("City: " & vbTab & vbTab & txtShipperCity.Text)
lbxLoad.Items.Add("State: " & vbTab & vbTab & cmbShipperState.Text)
lbxLoad.Items.Add("Phone: " & vbTab & vbTab & mtbShipperPhone.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add(" ")
lbxLoad.Items.Add("[Delivery Information] ")
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Delivery Date: " & vbTab & DateTimePicker2.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Receiver: " & vbTab & txtReceiver.Text)
lbxLoad.Items.Add("Address: " & vbTab & vbTab & txtReceiverAddress.Text)
lbxLoad.Items.Add("City: " & vbTab & vbTab & txtReceiverCity.Text)
lbxLoad.Items.Add("State: " & vbTab & vbTab & cmbReceiverState.Text)
lbxLoad.Items.Add("Phone: " & vbTab & vbTab & mtbReceiverPhone.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add(" ")
lbxLoad.Items.Add("[Mileage Information] ")
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Starting Mileage: " & vbTab & txtStartMileage.Text)
lbxLoad.Items.Add("Ending Mileage: " & vbTab & txtEndMileage.Text)
lbxLoad.Items.Add("Empty Miles: " & vbTab & txtEmptyMiles.Text)
lbxLoad.Items.Add("Loaded Miles: " & vbTab & txtLoadedMiles.Text)
lbxLoad.Items.Add("Total Miles: " & vbTab & txtTotalMiles.Text)
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add(" ")
lbxLoad.Items.Add("[Pay Information] ")
lbxLoad.Items.Add("*************************************************** ********************")
lbxLoad.Items.Add("Base Rate: " & vbTab & vbTab & "$" & txtBasePay.Text)
lbxLoad.Items.Add("Miles at Base Rate:" & vbTab & vbTab & "$" & txtTotalBase.Text)
lbxLoad.Items.Add("Per Diem Rate: " & vbTab & vbTab & "$" & txtPerDiemPay.Text)
lbxLoad.Items.Add("Miles at Per Diem rate:" & vbTab & "$" & txtTotalPerDiem.Text)
lbxLoad.Items.Add("Detention: " & vbTab & vbTab & "$" & txtTotalDetention.Text)
lbxLoad.Items.Add("Stops: " & vbTab & vbTab & vbTab & "$" & txtTotalStops.Text)
lbxLoad.Items.Add("Advances: " & vbTab & vbTab & "$" & txtTotalAdvances.Text)
lbxLoad.Items.Add("Total pay for trip: " & vbTab & vbTab & "$" & txtTotalPay.Text)

If lbxLoad.SelectedItems.Count = 1 Then
txtLoad.Text = lbxLoad.SelectedItem
End If
End Sub

All of the information in lbxLoad needs to be transferred to txtLoad.text preferably with the simple press of a button. Any suggestions?

I am willing to send more of the code and or the program itself if more information is needed, just ask.
Reply With Quote
  #2  
Old 12-18-2014, 04:25 PM
Gruff's Avatar
GruffSaving a Listbox orr adding a list box to a text file Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Not sure why your wanting to use a textbox to write to a file. You do not need it to do so.
Code:
Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Add four sample items to a listbox. With ListBox1 .Items.AddRange(New String() {"Cat", "Rat", "Dog", "Zebra"}) End With End Sub Private Sub cmdWriteListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdWriteListbox.Click 'Write listbox contents to a file With ListBox1 Dim LinesOfText(.Items.Count - 1) As String .Items.CopyTo(LinesOfText, 0) File.WriteAllLines("C:\MyTextFile.txt", LinesOfText) End With End Sub Private Sub cmdClearListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdClearListbox.Click 'Clear listbox of items ListBox1.Items.Clear() End Sub Private Sub cmdReadListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdReadListbox.Click 'Read text from file and fill a listbox With ListBox1 Dim LinesOfText = File.ReadAllLines("C:\MyTextFile.txt") .Items.AddRange(LinesOfText) End With End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 12-18-2014, 05:09 PM
Gruff's Avatar
GruffSaving a Listbox orr adding a list box to a text file Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Same thing but without the extra variables.
Code:
Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Add four sample items to a listbox. ListBox1.Items.AddRange(New String() {"Cat", "Rat", "Dog", "Zebra"}) End Sub Private Sub cmdWriteListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdWriteListbox.Click 'Write listbox contents to a file File.WriteAllLines("C:\MyTextFile.txt", ListBox1.Items.Cast(Of String).ToArray) End Sub Private Sub cmdClearListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdClearListbox.Click 'Clear listbox of items ListBox1.Items.Clear() End Sub Private Sub cmdReadListbox_Click(sender As System.Object, e As System.EventArgs) Handles cmdReadListbox.Click 'Read text from file and fill a listbox ListBox1.Items.AddRange(File.ReadAllLines("C:\MyTextFile.txt")) End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
 
Saving a Listbox orr adding a list box to a text file
Saving a Listbox orr adding a list box to a text file
 
-->