CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: sum function

  1. #1
    Join Date
    May 2001
    Location
    MO, USA
    Posts
    87

    sum function

    here is my code

    Sub SubComputeArea_Click()
    Dim sum, sum1, sum2
    sum1 = Text1: sum2 = Text2
    sum = (sum1 + sum2) ' add area of rectangle.
    Text3 = sum ' Print Area to Debug window.
    End Sub
    if change the + to *,/,- it works fine but as a + it returns the 2 numbers joined like this 5+5=55 or 2+2=22 not 5+5=10 what is worng here....

    thanx in advance
    midnightservice


  2. #2
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: sum function

    Hi,
    This is because '+' is a operater to connect two string, and by default, textbox contains string. Try this:

    =====

    Sub SubComputeArea_Click()
    Dim sum as long
    dim sum1 as long
    dim sum2 as long
    sum1 = clng(Text1)
    sum2 = clng(Text2)
    sum = (sum1 + sum2) ' add area of rectangle.
    Text3 = sum ' Print Area to Debug window.
    End Sub

    =====

    Regards,

    Michi

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