CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Posts
    11

    adding values in textboxes

    i have three text boxes and two command buttons. one command buttons add the values and the other takes away the values. i have got the take away command button to work but when i click on the add button istead of adding the value eg 10 + 10 = 20 it does 10 + 10 = 1010 please help


  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: adding values in textboxes

    Use

    Int(Val1) + int(Val2)

    Andrew


  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: adding values in textboxes

    This is because content of a textbox is string.
    text1.text = text1.text +10
    is equal to
    text1.text = text1.text & 10
    you can write
    (provided text1.text isnumeric)
    text1.text = cint(text1.text) +10
    or
    text1.text = cdbl(text1.text) +10
    or take suggest from previous reply...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Aug 2001
    Location
    Poland
    Posts
    6

    Re: adding values in textboxes

    You can use:
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
    it works also with non-integer values.

    Wojtek

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

Featured