a button that adds text to a textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iDaz
    New Member
    • Feb 2007
    • 5

    a button that adds text to a textbox

    hello! i have a textbox, and 2 buttons. this is what i would like:

    when i click button 1, "1" is added to the textbox. when i click button 2, "2" is added to the textbox.

    i have tried to do this myself, but when ever i click one of the buttons, it clears the digit that is already in the textbox, and then adds a new digit. i want it to keep adding digit after digit. eg. if i press button 1 three time, then button 2 twice, the textbox shows "11122". then if i press button 1 again, it adds a one to the end of the text, making it read "111221", etc.

    any help would be much appreicated!
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Originally posted by iDaz
    hello! i have a textbox, and 2 buttons. this is what i would like:

    when i click button 1, "1" is added to the textbox. when i click button 2, "2" is added to the textbox.

    i have tried to do this myself, but when ever i click one of the buttons, it clears the digit that is already in the textbox, and then adds a new digit. i want it to keep adding digit after digit. eg. if i press button 1 three time, then button 2 twice, the textbox shows "11122". then if i press button 1 again, it adds a one to the end of the text, making it read "111221", etc.

    any help would be much appreicated!
    No problem!

    If your textbox was called TextBox1 then after

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    for each button put

    Code:
    TextBox1.Text = ""
    Then under that should be your code to add the text in.

    Hope that helps!

    Comment

    • devonknows
      New Member
      • Nov 2006
      • 137

      #3
      Just another quick suggestion it its any easier in your Command#_Click sub section you could just enter something as simple as

      Code:
      TextBox1.Text = TextBox1.Text & 2 'For Command1
      TextBox1.Text = TextBox1.Text & 1 'For Command2
      Not Sure you would find easier to work with but a quick demo is below
      Code:
      Private Sub Command1_Click()
          Text1.Text = Text1.Text & 1
      End Sub
      
      Private Sub Command2_Click()
          Text1.Text = Text1.Text & 2
      End Sub
      Kind Regards
      Devon.

      Comment

      • manojkapparath
        New Member
        • Jan 2007
        • 5

        #4
        Originally posted by iDaz
        hello! i have a textbox, and 2 buttons. this is what i would like:

        when i click button 1, "1" is added to the textbox. when i click button 2, "2" is added to the textbox.

        i have tried to do this myself, but when ever i click one of the buttons, it clears the digit that is already in the textbox, and then adds a new digit. i want it to keep adding digit after digit. eg. if i press button 1 three time, then button 2 twice, the textbox shows "11122". then if i press button 1 again, it adds a one to the end of the text, making it read "111221", etc.

        any help would be much appreicated!
        Suppose Your TextBox be Text1.
        When you press a Button, Say Cmd_One (for 1)
        Write the Code
        Text1.Text = Text1.Text & "1"

        When you press a Button, Say Cmd_Two (for 2)
        Write the Code
        Text1.Text = Text1.Text & "2"

        Now it will Work Effectively.

        Comment

        • markmcgookin
          Recognized Expert Contributor
          • Dec 2006
          • 648

          #5
          Originally posted by markmcgookin
          No problem!

          If your textbox was called TextBox1 then after

          Code:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          for each button put

          Code:
          TextBox1.Text = ""
          Then under that should be your code to add the text in.

          Hope that helps!

          Hehe, I just re-read your post and realised I gave you the totally wrong answer....

          lol something nice and easy would be

          Code:
          Dim Temp as String
          Temp = TextBox1.Text
          Temp = Temp & 1     'For button 1 and ... Temp = Temp & 2 for button 2
          TextBox1.Text = Temp

          Comment

          • iDaz
            New Member
            • Feb 2007
            • 5

            #6
            WOW thank you very much everyone for your help!! i really do appreciate it! you've just helped me complete an assignment for my IT course! thank you all!

            Comment

            Working...