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

    adding 2 variables

    I want the user to enter 2 numbers in 2 different text boxes and store them in 2 variables:

    Dim num1 as single
    Dim num2 as Single
    num1 =Text1.text
    num2 = Text2.text



    Now when the user clicks on a command button, i want it to add the to text boxes and put the answer in another text box:

    private Sub Figureout_Click()
    Dim add as string
    add = num1 + num2
    Text3.text = add
    End Sub



    but when i do that myself, say i put 1 in the first text box and 2 in the 2nd text box. It comes out: 12.

    Does any1 know how to make it come out 3 instead of 12???

    --Ant
    ------------------------------------------------------------------------------------------------------------------------
    Want Free Software?
    E-mail me @: [email protected]

  2. #2
    Join Date
    Aug 2000
    Location
    Namibia
    Posts
    139

    Re: adding 2 variables

    Dimension add as any numeric datatype

    e.g. dim add as integer




  3. #3
    Join Date
    May 2001
    Location
    Israel
    Posts
    9

    Re: adding 2 variables

    Hi You Should Define the Add as a single also and use the Val and Str Functions.
    Try this code in your function:


    Dim add as Single
    num1 = Val(Text1.Text)
    num2 = Val(Text2.Text)
    add = num1 + num2
    Text3.Text = Str(add)




    I hope this solves your problem.


  4. #4
    Join Date
    May 2001
    Posts
    155

    Re: adding 2 variables

    Thanks!

    That solved my problem




    --Ant
    ------------------------------------------------------------------------------------------------------------------------
    Want Free Software?
    E-mail me @: [email protected]

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