Results 1 to 7 of 7

Thread: maths help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    london
    Posts
    31
    im trying to get vb to add up a list of fig held in text boxs

    eg

    a = text1.text
    b = text2.text
    c = a + b
    text3.text = c

    with 10 in both text1 and text2 i was hopping for 20 in text3 but i am getting 1010 can anybody please help.

    Thanks

    Dave
    D Stonebanks

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Either use val function to get a numeric expression or declare your variables as integers
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Member
    Join Date
    May 2000
    Location
    Mansfield Texas
    Posts
    36
    don't ask me why this works.
    [code]
    Private Sub Command1_Click()
    Text3.Text = (Text2) * (Text1) / (Text1) + (Text1)

    End Sub
    Charlie Staton
    14 y/o
    I don't smoke, I don't drink, and I don't assosciate with pokemon.

  4. #4
    Guest
    Dave ~

    I'm new to this as well and learning on my own too. This is a great place for advice! Super helpful people here!

    I created a quick form and tried this out so it should work for you.

    On the form I created three text boxes and one command button, named cmdAdd. Hope this helps you!

    Code:
    Private Sub cmdAdd_Click()
    
    'Declare numbers you wish to add as Integers.
    Dim intA As Integer, intB As Integer
    
    
    intA = txtA.Text
    intB = txtB.Text
    
    txtC.Text = intA + intB 
    
    End Sub

  5. #5
    Guest
    Hello,

    You could also use this:
    Code:
    a = Cint(text1.text) ' change to an integer
    b = Cint(text2.text) 
    c = a + b 
    text3.text = c
    Check the help files for Cint, and see the other types you can change to.

    Hope this helps,

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    VAL(expression) gives you any values from strings
    CINT(expression) Rounds your value to the nearest whole
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    Just to give the example of Val...

    Private Sub cmdAdd_Click()

    Text3.Text = Val(Text1.Text) + (Text2.Text)

    End Sub

    The Val converts the string to a numeric value

    GRAHAM

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