|
-
Apr 28th, 2011, 01:55 PM
#1
Thread Starter
Addicted Member
adding text to multiline textbox without erasing previous contents
how do i add text to a multiline textbox without erasing what is already in there?
Lets say the textbox already has...
"Visual basic is "
and then i want to add the word "fun" to the textbox without erasing "Visual basic is "
after adding "fun" i want it to read....
"Visual basic is fun"
any ideas?
-
Apr 28th, 2011, 01:58 PM
#2
Re: adding text to multiline textbox without erasing previous contents
well... think of your text box as a variable... if you have "Visual Basic 6 is " in a variable and you want to concatenate text to it, how would you go about doing that?
-tg
-
Apr 28th, 2011, 04:32 PM
#3
Lively Member
Re: adding text to multiline textbox without erasing previous contents
I had a similar problem while trying to add text in my Text Adventure game...
What I did was, whenever I want the game to add something new to the textbox without reasing the old thing I'd put:
textbox1.text = textbox1.text + " fun"
Hope this is what you were looking for.
-
Apr 28th, 2011, 06:56 PM
#4
Re: adding text to multiline textbox without erasing previous contents
vb Code:
textbox1.text &= "new text"
to put "new text" on a new line:
vb Code:
textbox1.text &= environment.newline & "new text"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 28th, 2011, 07:24 PM
#5
Fanatic Member
Re: adding text to multiline textbox without erasing previous contents
I wasn't familiar with &= I would have coded it like
Code:
textbox1.Text = textbox1.Text & "new text"
I see that & and + are interchangeable. So you could code it
Code:
textbox1.text &= "new text" ' Or
textbox1.text += "new text" ' And
textbox1.text = textbox1.Text & "new text" ' is the same thing as
textbox1.text = textbox1.Text + "new text"
At least they're the same as far as I can see but maybe there's some behavioral difference under certain circumstances. I noticed that you can also put + and & in the same equation without a problem which makes sense since they do the same thing.
Code:
textbox1.text += "new text" & " some other text" + " and still more text"
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Apr 28th, 2011, 07:27 PM
#6
Re: adding text to multiline textbox without erasing previous contents
+ is also used for addition. so with option strict off these 2 strings:
"10" & "10" = "1010"
"10" + "10" = 20
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 28th, 2011, 09:16 PM
#7
Re: adding text to multiline textbox without erasing previous contents
If you want to append text to a TextBox then call the AppendText method of that TextBox.
-
Apr 17th, 2013, 04:12 AM
#8
New Member
Re: adding text to multiline textbox without erasing previous contents
HOOORAY!
I got it to work using TextBox2.Text &= Environment.NewLine & "entered my stuff here" 
Thanks all for the help and ideas.
-
Apr 17th, 2013, 02:48 PM
#9
Re: adding text to multiline textbox without erasing previous contents
Yippee. Now do it the proper way using the AppendText method like jmc told you to!!!! I can't believe the number of people, including some very advanced coders, who seem to be completely ignorant of this method!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 17th, 2013, 09:32 PM
#10
Re: adding text to multiline textbox without erasing previous contents
considering that james' posting was almost exactly two years ago... I'm not surprised... people often just find the first thing that works and stop reading.
-tg
-
Apr 17th, 2013, 09:41 PM
#11
Re: adding text to multiline textbox without erasing previous contents
 Originally Posted by dunfiddlin
Yippee. Now do it the proper way using the AppendText method like jmc told you to!!!! I can't believe the number of people, including some very advanced coders, who seem to be completely ignorant of this method!
there are often several ways to skin a cat, + in this case both are proficient uses of the language.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 17th, 2013, 09:58 PM
#12
Re: adding text to multiline textbox without erasing previous contents
 Originally Posted by .paul.
there are often several ways to skin a cat, + in this case both are proficient uses of the language.
They don't produce quite the same behaviour though and, generally speaking, the behaviour of AppendText is more desirable. I wouldn't call setting the Text property wrong though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|