|
-
Dec 1st, 2011, 03:16 PM
#1
Thread Starter
Member
[VB.NET] Very Simple TextBox Problem
Im having a problem with this code:
Code:
TextBox1.Text = (TextBox1.Text + "hello")
I want it do add "Hello" when someone clicks a button that changes the text of TextBox1. Im doing something wrong as the program crashes. What am i doing wrong?
-
Dec 1st, 2011, 04:00 PM
#2
Re: [VB.NET] Very Simple TextBox Problem
Make sure option strict is on. Try this.
Code:
TextBox1.Text &= "hello"
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Dec 1st, 2011, 04:04 PM
#3
Lively Member
Re: [VB.NET] Very Simple TextBox Problem
Very Simple, and easy to fix:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text += "hello"
End Sub
That should do it!
<-- If you like my post, click on the  to the left! It only takes a second... 
-
Dec 1st, 2011, 04:07 PM
#4
Re: [VB.NET] Very Simple TextBox Problem
 Originally Posted by CoderKid
Very Simple, and easy to fix:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text += "hello"
End Sub
That should do it! 
Generally when adding "plus" together we use &= as wild_bill showed. Not +=. += is generally used for integers.
-
Dec 1st, 2011, 04:10 PM
#5
Lively Member
Re: [VB.NET] Very Simple TextBox Problem
You could also, to make the program more advanced, add another textbox that allows the user to choose his own text to be inputted into the textbox1:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Message As String = TextBox2.Text
TextBox1.Text += " " & Message
TextBox2.Text = " "
End Sub
That is just a more advanced way of doing it. Basically, it just gets the text in TextBox2 by declaring a variable, and that variable is the text added to TextBox1.
Good luck!
<-- If you like my post, click on the  to the left! It only takes a second... 
-
Dec 1st, 2011, 04:14 PM
#6
Lively Member
Re: [VB.NET] Very Simple TextBox Problem
 Originally Posted by ident
Generally when adding "plus" together we use &= as wild_bill showed. Not +=. += is generally used for integers.
You're right....I'm just so used to using the plus sign. Maybe I should start using the & sign...
Thanks for your insights!
<-- If you like my post, click on the  to the left! It only takes a second... 
-
Dec 2nd, 2011, 11:37 AM
#7
Re: [VB.NET] Very Simple TextBox Problem
I'm pretty sure I originally used AND in VB3... when I updated to VB5, It didn't like AND anymore and & was the next logical choice...
I'm also pretty sure that VB3 didn't like using +... so I just learned how to do it by default.
-
Dec 2nd, 2011, 03:46 PM
#8
Thread Starter
Member
Re: [VB.NET] Very Simple TextBox Problem
Ok, i finally managed. Thanks guys for all the help!
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
|