Results 1 to 8 of 8

Thread: [VB.NET] Very Simple TextBox Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    47

    [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?

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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

  3. #3
    Lively Member CoderKid's Avatar
    Join Date
    Oct 2011
    Location
    In the middle of nowhere
    Posts
    72

    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...

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [VB.NET] Very Simple TextBox Problem

    Quote Originally Posted by CoderKid View Post
    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.

  5. #5
    Lively Member CoderKid's Avatar
    Join Date
    Oct 2011
    Location
    In the middle of nowhere
    Posts
    72

    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...

  6. #6
    Lively Member CoderKid's Avatar
    Join Date
    Oct 2011
    Location
    In the middle of nowhere
    Posts
    72

    Re: [VB.NET] Very Simple TextBox Problem

    Quote Originally Posted by ident View Post
    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...

  7. #7
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    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.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    47

    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
  •  



Click Here to Expand Forum to Full Width