-
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
-
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