View Full Version : vb adding problem

04-07-2004, 06:05 PM
can someone tell me whats wrong with this code? :o
when i type two numbers to be added, it just puts the numbers together, like 12+12 = 1212. I dont understand whats wrong here:

dim a, b, answer
a = inputbox ("What is the first number? ")
b = inputbox ("What is the second number? ")
answer = a+b
msgbox ("The sum is " & answer )

04-07-2004, 06:09 PM
The return value from InputBox is a string, so VB is just doing it's "string addition", which is concatenation.
You need to cast the variables to Integer before you add them:

' you should also be using the IsNumeric function before this to check
' that the values entered are actually numbers, otherwise the CInt() calls
' will give you a runtime error
answer = CInt(a)+CInt(b)