Im having a problem with this code: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?Code:TextBox1.Text = (TextBox1.Text + "hello")
Printable View
Im having a problem with this code: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?Code:TextBox1.Text = (TextBox1.Text + "hello")
Make sure option strict is on. Try this.
Code:TextBox1.Text &= "hello"
Very Simple, and easy to fix:
That should do it!:DCode:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text += "hello"
End Sub
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:
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.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
Good luck!
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.
Ok, i finally managed. Thanks guys for all the help!