English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How do I get visual Basic .NET to load each line of a saved file into s a separate textbox.

For example, I want to load test.txt which has two lines.
1. This is line one.
2. This is line two.

I want each line to load into a separate textbox. Thank you!

2006-12-29 18:21:45 · 2 answers · asked by stultz_is 2 in Computers & Internet Programming & Design

2 answers

Dim myfile As String = "yourfile.txt"


Dim x As Integer
Dim line(4) As String

Dim Read As New System.IO.StreamReader(myfile)
For x = 0 To 1
line(x) = Read.ReadLine
Next x

Dim server As String
Dim username As String
server = line(0)
username = line(1)
Read.Close()

Textbox1.Text = server
Textbox2.Text = username

2006-12-30 16:58:17 · answer #1 · answered by deccasoftware 3 · 0 0

Well, forgive me i do c#, but this is what i'd do.

TextBox[] textboxArray;
List data = new List();
FileStream file = File.Open("myfile.txt", FileMode.Open);
StreamReader reader = new StreamReader(file);
while (!reader.EndOfStream)
{
data.Add(reader.ReadLine());
}
reader.Close();
file.Close();
textboxArray = new TextBox[data.Count];//create a text box for each line
for (int x = 0; x < data.Count; x++)
{
textboxArray[x].Text = data[x];
this.Controls.Add(textboxArray[x]);
}

2006-12-31 19:29:24 · answer #2 · answered by Jhered 3 · 0 0

fedest.com, questions and answers