Results 1 to 4 of 4

Thread: this is real silly....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    Just now I realize that I have never had to do basic equations in any of my little programs while learning VB, so I must ask something that may seem a little ridiculous...

    Here's a basic way of explaining my question:

    3 text boxes on a form (txt1,txt2,txt3)
    1 command button (cmd1)

    Say I want to add txt1 and txt2 and display result in txt3.
    The command button to perform the calc.

    This is what I've done:



    Private Sub cmdCalc_Click()
    x = Text1
    y = Text2

    Text3 = x + y
    End Sub

    Plus several other variations of the same.
    As I'm sure you all realize, with what I've done, if txt1 =2 and txt2 = 2, txt3 displays "22"

    What am I forgetting to do?

    Thank you.

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    Use this code:

    Code:
    ----------------
    x=val(txt1)
    y=val(txt2)
    txt3=x+y
    ---------------

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [code]
    'textboxes are string by default so you have to
    'convert using Cint,Cdbl,Clnt or use Val for value
    'assuming textboxes are txt1,txt2,txt3
    'you don't need the variables

    Private Sub cmdCalc_Click()
    txt3 = val(txt1) + val(txt2)
    End Sub
    [code]

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Guest
    Use CInt if your numbers does not involve decimals.
    Code:
    txt3 = CInt(txt1) + CInt(txt2)

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