Results 1 to 7 of 7

Thread: [RESOLVED] from buttons to textbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Location
    wv
    Posts
    21

    Resolved [RESOLVED] from buttons to textbox

    i'm new to vb.net and am having a little trouble with a textbox. i'm using vb 2010 and am trying to make a calculator with a form. i've got the buttons with numbers that display the number in the box when it is clicked on, but the next button clicked on replaces the previous value instead of adding to it. i've downloaded 2 calculator examples, but the code is way beyond me, i can't even figure out where the box is in either of them. it seems that when i tell the button to put the variable in the box there would be some way to tell it to add the new number instead of replace the number, but i can't figure out what it would be. this is going to be a group project later in the quarter, but i'm doing it for the learning experience now.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: from buttons to textbox

    If you set the Text of a TextBox to 1, it will display 1, right? Now, if you set the Text to 2, what would you expect it to display? The TextBox always displays the contents of its Text property, so it will display 2. If you want to join the existing text with some new text, that's exactly what you have to do: get the current Text, join the new text to it and then assign that combined result to the Text property, which then gets displayed.

    Even better, the TextBox class even has a method specifically to append text. It's named AppendText. I know you are a beginner but, regardless, you should ALWAYS read the documentation. You're using a TextBox. Read the documentation for the TextBox class. Looking down the list of members, you'd soon come across the AppendText method, described thusly:
    Appends text to the current text of a text box.
    Beginner or not, it should be fairly clear that that does exactly what you want.

    If you don't find what you want in the documentation then haven't really lost anything, other than a few minutes looking. If you do find it then it's a win, and you may find other useful information besides.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Location
    wv
    Posts
    21

    Re: from buttons to textbox

    it has a lot to do with information overload. i got a 1400 page book from the library, and of course the internet, to search through. i figured out basically what to do, just couldn't find an example for syntax. thanx so much for providing the light to the path, i was wandering in the dark. if it had been basic and not visual basic, i think i still have a calculator program that ran on a ti 99-4a saved on a tape drive(i guess that's dating myself as ancient).

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: from buttons to textbox

    Quote Originally Posted by sfzombie13 View Post
    it has a lot to do with information overload.
    That's exactly why I say (many times, if you care to check some of my older posts) to always read the documentation first. There's sifting or searching. If you know what type and/or member you are using, go straight to the documentation for that type and/or member and read. If you find what you need, as you would in this instance, there's no need to look any further, so you won't get overloaded.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Location
    wv
    Posts
    21

    Re: [RESOLVED] from buttons to textbox

    apparently i was a bit hasty in marking this thread resolved. i worked for about 2 hours last night and couldn't make use of the append text command. in the book it says that it's used to append text to a file, not a text box. maybe i'm missing something, and what the hell happened to the other reply to this thread? i saw it briefly, and it had an email to me that it was posted, but when i came back to the thread, it wasn't there.
    i'm gonna try to muddle my way through this and i will solve the problem. i guess i'm gonna have to read the code i downloaded line by line.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [RESOLVED] from buttons to textbox

    Append text also relates to TextBox's as mentioned earlier. Click AppendText from the list of members.
    Last edited by Bruce Fox; Jan 15th, 2011 at 01:56 PM.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] from buttons to textbox

    The method to append text to a TextBox is TextBox.AppendText. The File.AppendText creates a StreamWriter that is pre-configured to append text to a file. It depends what you call the method on.

    With regards to documentation, you should start with the class and go from there. Personally, I usually use the local version of the MSDN documentation but, using the online version, you'd start here:

    http://msdn.microsoft.com/en-AU/

    then find the topic for the TextBox class:

    http://social.msdn.microsoft.com/Sea...7;20class&ac=3

    read the overview:

    http://msdn.microsoft.com/en-us/libr...s.textbox.aspx

    then click the link for any members that look relevant:

    http://msdn.microsoft.com/en-us/libr...ppendtext.aspx
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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