|
-
Nov 8th, 2005, 01:34 PM
#1
Thread Starter
Member
adding up 2 strings
i have strA and strB
strA = 1
strB = 1
i try text1.text = strA + strB
but it doesn't work the result is 11 not 2 why?
-
Nov 8th, 2005, 01:37 PM
#2
Re: adding up 2 strings
 Originally Posted by vbcooler
i have strA and strB
strA = 1
strB = 1
i try text1.text = strA + strB
but it doesn't work the result is 11 not 2 why?
VB Code:
Text1.Text = Val(strA) + Val(strB)
Also, if you are going to be adding these together, they should be declared as integers
VB Code:
Dim intA As Integer
Dim intB As Integer
Then, you wouldn't need to Val them.
-
Nov 8th, 2005, 02:06 PM
#3
Thread Starter
Member
Re: adding up 2 strings
 Originally Posted by Hack
VB Code:
Text1.Text = Val(strA) + Val(strB)
Also, if you are going to be adding these together, they should be declared as integers
VB Code:
Dim intA As Integer
Dim intB As Integer
Then, you wouldn't need to Val them.
THEY CAN'T BE DECLER AS AN INTEGER SINCE SOME OF THE NUMBERS COULD BE
1.3
5.5
ETC..
-
Nov 8th, 2005, 02:07 PM
#4
Re: adding up 2 strings
Declare them as Long, single or double then
-
Nov 8th, 2005, 02:15 PM
#5
Re: adding up 2 strings
 Originally Posted by Atheist
Declare them as Long, single or double then
A Single or a Double would return decimals. A Long will round to an even number.
-
Nov 8th, 2005, 02:19 PM
#6
Re: adding up 2 strings
 Originally Posted by Hack
A Single or a Double would return decimals. A Long will round to an even number.
oh yes youre right
-
Nov 8th, 2005, 02:31 PM
#7
Addicted Member
Re: adding up 2 strings
Long will truncate to an integer, not round to an even number!
Right?
-
Nov 8th, 2005, 02:35 PM
#8
Re: adding up 2 strings
Wrong. If you have this statement
Long = Double + Double
The Double + Double would be rounded to the nearest integer.
-
Nov 8th, 2005, 02:43 PM
#9
Addicted Member
Re: adding up 2 strings
Not all "Wrong"...
Long does indeed round a number (I thought it truncated it ), but it doesn't necessarily round to an EVEN number (1.3 gets rounded to 1 - an ODD number).
Now I think we're straight!
-
Nov 8th, 2005, 02:46 PM
#10
Re: adding up 2 strings
 Originally Posted by Set me As newtype
Not all "Wrong"...
Long does indeed round a number (I thought it truncated it  ), but it doesn't necessarily round to an EVEN number (1.3 gets rounded to 1 - an ODD number).
Now I think we're straight!
Ok, I misspoke. Long doesn't round to an even number it rounds to a whole number (which is actually what I meant but not what I typed.)
-
Nov 8th, 2005, 03:38 PM
#11
Re: adding up 2 strings
 Originally Posted by vbcooler
i have strA and strB
strA = 1
strB = 1
i try text1.text = strA + strB
but it doesn't work the result is 11 not 2 why?
..... the result is 11 not 2 why?[/
The '+' serves to join (concatenate) Strings. However, If you want to concatenate Strings, then
the appropriate operator is the '&' (ampersand), noting the '+' will do the same. Hence, you got '11' and not a mathematecal add equaling 2.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|