Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes
Read textfile lines to text boxes Read textfile lines to text boxes
Read textfile lines to text boxes
Go Back  Xtreme Visual Basic Talk > > > Read textfile lines to text boxes


Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2012, 01:45 PM
gnappi gnappi is offline
Freshman
 
Join Date: Mar 2006
Posts: 33
Default Read textfile lines to text boxes


I have an application that I wrote to save the fields of combo boxes, and textboxes into a text file. I want to read the file, and send the lines to their original locations. The output of the save file looks like this:

Filename.txt
Restaurant
text here
12345
1200
0
0
something
33
111
text
None

The fields are saved with: oWrite.WriteLine(TextBox1.Text)
Even fields with no selection or input will have a zero in them so the locations will always be static.

I can write them all into a single text box, but recalling a form must have the original data displayed in them. Any help would be appreciated.
Reply With Quote
  #2  
Old 07-18-2012, 04:56 PM
Gruff's Avatar
GruffRead textfile lines to text boxes Gruff is offline
Bald Mountain Survivor

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

If you are trying to save and restore the content of multple controls in one text file then I think you are going to have to have some sort of delimiters that separate each control's content inside the text file.

If as you say the controls are static you could simply read each control datablock and fill the expected control serially. i.e. you know the first block is data for textbox-A so you hard code filling that one first. Next, Etc...

Another method might be to define the control by name side each block as well as the control type, then fill that contol by the control type method.

Such a text block might look like this.

BLOCK BEGIN
TextboxA
TextBox
This is the content of the text file
The quick brown fox jumps over the lazy dog.
This is the third line
BLOCK END

BLOCK BEGIN
...


Another approach might be to use an XML file
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 07-18-2012 at 05:08 PM.
Reply With Quote
  #3  
Old 07-19-2012, 06:35 AM
gnappi gnappi is offline
Freshman
 
Join Date: Mar 2006
Posts: 33
Default

I was not clear in my description. Most input boxes will be user input and not static. They will only be static if the user does not select a field for update. Imagine a shopping cart for a vegetable department where every vegetable there has a field and if a shopper adds 6 peaches and not apples. The apple field will be zero while the peach field will be 6.

Adding a delimiter is rather easy, with oWrite.WriteLine(TextBox12.Text + delimiter) (in this case a comma) but getting individual textboxes back into their original places and stripping out the comma would be my problem

Any guidance would be appreciated
Reply With Quote
  #4  
Old 07-19-2012, 10:00 AM
Gruff's Avatar
GruffRead textfile lines to text boxes Gruff is offline
Bald Mountain Survivor

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

By static I simply meant that the order in which the each control's data is written is the same as the order in which it is read. textbox1, textbox2, combobox1, textbox3,...

In any case the following would read a file with text blocks as defined above into the form controls.
I am sure you can alter it to work for you.
--- Untested Code Follows ---
Code:
Imports System.IO Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim sLines() As String = File.ReadAllLines("c:\SaveState.txt") Dim i As Integer = 0 Do If sLines(i) = "BLOCK BEGIN" Then Dim sTitle As String = sLines(i + 1) Dim sType As String = sLines(i + 2) i += 3 Dim sData As New List(Of String) Do sData.Add(sLines(i)) i += 1 Loop Until sLines(i) = "BLOCK END" If sType = "TextBox" Then Dim txt As TextBox = CType(Me.Controls(sTitle), TextBox) txt.Text = String.Join(vbCrLf, sData.ToArray) ElseIf sType = "ComboBox" Then Dim cbo As ComboBox = CType(Me.Controls(sTitle), ComboBox) cbo.Items.AddRange(sData.ToArray) End If End If i += 1 Loop Until i > sLines.Count - 1 End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 07-19-2012 at 01:24 PM.
Reply With Quote
  #5  
Old 07-20-2012, 03:58 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default saving application information and user settings dynamically

Of course gruff's code would work, but isn't there supposed to be
something in .Net made specifically for saving application (and user) settings?

I guess there was a lot of "confusion" so someone had to write an article on
"Application Settings in VB.NET".

This MSDN Application Settings page also has a section called
"Accessing or Changing Application Settings at Run Time in Visual Basic"
which will lead you to the "Accessing Application Settings (Visual Basic)"
page
and the My.Settings object.

However, I've only begun to play around with such things..

For now (being a old-style VB6 guy just trying to transition over to VB.Net)
I still use .ini files to store information like this,
but instead of having to PInvoke API calls,
I use the updated VB.Net way for handling ini files,
shown in the INI_Sampler attached to this post.

Last edited by surfR2911; 07-20-2012 at 04:32 PM.
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
Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes Read textfile lines to text boxes
Read textfile lines to text boxes
Read textfile lines to text boxes
 
Read textfile lines to text boxes
Read textfile lines to text boxes
 
-->