473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mulitline textboxes

I'm a real newbie so I apologize for the easy question. I have academic
version of vb.net 2003.
I am trying to write a multiline textbox with data from a text file.
Properties for the textbox are multiline = true, scrollbars = both, wordwrap
= false.

I actually have two textboxes side by sied for different files and I am
using a splitter.
Here is code for reading from one file to populate the text box. I always
end up with the last line of the file.
'open the first file and display

Dim strText1 As String

If strTextFileName1 <> "" Then

Label1.Text = strTextFileName1

objTextRead1 = System.IO.File.OpenText(strTextFileName1)

Me.LeftTextbox.Text = strTextFileName1

Do Until objTextRead1.Peek = -1

strText1 = objTextRead1.ReadLine()

Me.LeftTextbox.Text = strText1

Loop

objTextRead1.Close()

End If

Any help is appreciated. Thank you. Thom
Nov 20 '05 #1
4 1116
Thom,

What you are doing is storing different values one after another to the
default or first line of the textbox. Naturally the last line stored would
be the one remaining at the end. There are several ways to do what you want,
but I think the one which you will be able to use right away is this one.
Declare a counter and increase it in your loop and use the counter to access
the "Lines" property of the textbox. Also there are better ways to determine
that you have read a line and better ways to detect end of file, but I won't
go into them.

Like so...

Dim strText1 As String

If strTextFileName1 <> "" Then

Label1.Text = strTextFileName1

objTextRead1 = System.IO.File.OpenText(strTextFileName1)

Me.LeftTextbox.Text = strTextFileName1

Dim ACounter as integer = 0

Do Until objTextRead1.Peek = -1 'Check out the while loop and the .Read
property

strText1 = objTextRead1.ReadLine()

Me.LeftTextbox.Lines(ACounter) = strText1
ACounter = ACounter + 1
Loop

objTextRead1.Close()

End If
"Thom" <la*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
I'm a real newbie so I apologize for the easy question. I have academic
version of vb.net 2003.
I am trying to write a multiline textbox with data from a text file.
Properties for the textbox are multiline = true, scrollbars = both, wordwrap = false.

I actually have two textboxes side by sied for different files and I am
using a splitter.
Here is code for reading from one file to populate the text box. I always
end up with the last line of the file.
'open the first file and display

Dim strText1 As String

If strTextFileName1 <> "" Then

Label1.Text = strTextFileName1

objTextRead1 = System.IO.File.OpenText(strTextFileName1)

Me.LeftTextbox.Text = strTextFileName1

Do Until objTextRead1.Peek = -1

strText1 = objTextRead1.ReadLine()

Me.LeftTextbox.Text = strText1

Loop

objTextRead1.Close()

End If

Any help is appreciated. Thank you. Thom

Nov 20 '05 #2
* "Thom" <la*****@charter.net> scripsit:
I actually have two textboxes side by sied for different files and I am
using a splitter.
Here is code for reading from one file to populate the text box. I always
end up with the last line of the file.
'open the first file and display

Dim strText1 As String

If strTextFileName1 <> "" Then

Label1.Text = strTextFileName1

objTextRead1 = System.IO.File.OpenText(strTextFileName1)

Me.LeftTextbox.Text = strTextFileName1

Do Until objTextRead1.Peek = -1

strText1 = objTextRead1.ReadLine()

Me.LeftTextbox.Text = strText1


Replace the line above with 'Me.LeftTextBox.Text &= strText1'.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!
Nov 20 '05 #3

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
* "Thom" <la*****@charter.net> scripsit:
I actually have two textboxes side by sied for different files and I am
using a splitter.
Here is code for reading from one file to populate the text box. I always end up with the last line of the file.
'open the first file and display

Dim strText1 As String

If strTextFileName1 <> "" Then

Label1.Text = strTextFileName1

objTextRead1 = System.IO.File.OpenText(strTextFileName1)

Me.LeftTextbox.Text = strTextFileName1

Do Until objTextRead1.Peek = -1

strText1 = objTextRead1.ReadLine()

Me.LeftTextbox.Text = strText1


Replace the line above with 'Me.LeftTextBox.Text &= strText1'.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!


Thanks Gents I appreciate the help. I used Herfried's example. Works like a
champ.
Thanks again.
Thom
Nov 20 '05 #4
* "Thom" <la*****@charter.net> scripsit:
Thanks Gents I appreciate the help. I used Herfried's example. Works like a
champ.


Notice that, for large files, using a 'StringBuilder' for building the
string and then assinging its 'ToString' return value to the textbox's
'Text' property will be faster.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: T. Wintershoven | last post by:
Hello, I have a few textboxes placed on a SSTab control devided over 3 tabs Is there a way to clear all textboxes in one time in stead of one by one. Someone told me "Use for each item...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
1
by: Edlueze | last post by:
I have a number of forms with large textboxes for the purposes of editing memo fields, and just recently I've noticed some bizarre behavior. For some textboxes the END and HOME keys do nothing,...
11
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
4
by: Jason M | last post by:
Hi, Im very new to c#, so forgive me if this is a really stupid question. Im trying to create a form for entering purchase requests. For each line item I have a quantity, a description unit cost...
1
by: Kottan1970 | last post by:
I have a problem using a mulitline TextBox in .NET 1.1 with SmartNavigation. The text wrapping doesn't work correctly. If I click into the textarea and click ESCAPE the text is displayed correctly....
1
by: amurra06 | last post by:
I have a form that contains a tabpage and in that tabpage is a usercontrol that conatins a bunch of textboxes. I have arranged these textboxes in groupboxes to organize them better. What I do is to...
8
by: clintonG | last post by:
I have to get to this later tonight or tommorrow...and wonder... There's two TextBoxes in a Wizard Step posing an either-or situtation. Only one or the other TextBox may pass data. The...
3
by: sakhan | last post by:
Hello Friends, I want to create a row of 10 textboxes each time I click the add button. I want this to continue till it reaches five hundred I am using AJAX for this. It doesnot create 10...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.