Results 1 to 4 of 4

Thread: Adding up

  1. #1

    Thread Starter
    Hyperactive Member tomjess's Avatar
    Join Date
    Mar 2001
    Location
    Hamilton, New Zealand
    Posts
    348

    Adding up

    I have 5 text boxes. When I put a number in the first text box I want the same number to appear in the 5th text box. When I put a number in the second text box I want it to appear in the 5th text box, but now its added to the the first number and so on to the fourth text box. I want this to happen as the user types in the numbers.

    Thanks in advance

  2. #2
    Addicted Member
    Join Date
    Mar 2002
    Location
    Lithuania
    Posts
    165
    VB Code:
    1. text5.text=text1.text & text2.text
    P.S. Sorry for my poor English...

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. Private Sub Text1_Change()
    2.     Text5.Text = CLng(Text1.Text) + CLng(Text2.Text)
    3. End Sub

    You should use a control array and loop through the textboxes if you're going to be adding more than just the two TextBoxes
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Are you trying to add the number entered into each texbox to your 5th textbox ?

    could try this I guess?
    VB Code:
    1. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    2.     Text5.Text = Val(Text5.Text) + Val(Text1.Text)
    3. End Sub
    4. Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
    5.     Text5.Text = Val(Text5.Text) + Val(Text2.Text)
    6. End Sub
    7. Private Sub Text3_KeyUp(KeyCode As Integer, Shift As Integer)
    8.     Text5.Text = Val(Text5.Text) + Val(Text3.Text)
    9. End Sub
    10. Private Sub Text4_KeyUp(KeyCode As Integer, Shift As Integer)
    11.     Text5.Text = Val(Text5.Text) + Val(Text4.Text)
    12. End Sub
    but like plenderj said, you'd be better off using control array for this purpose.
    Last edited by daydee; Apr 22nd, 2003 at 03:08 AM.
    Give your music collection a whole new life with PartyTime Jukebox

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