3336Views13Replies

Author Options:

VBScript Addition Problems? Answered

Hello I Have a Addition Problem In VBScript.

If i use 2 Inputboxes to get to numbers (Lets say 3 and 5), there both numeric (isNumeric return "True"), but when i add them (c=a+b) and then msgbox 'c' it comes up '35' not 8. PLEASE HELP ME

13 Replies

user
aelias36Best Answer (author)2011-02-17

try c=CInt(a)+CInt(B)

This makes sure that you're adding integers, not strings.

Select as Best AnswerUndo Best Answer

user
frollard (author)aelias362011-02-17

right, isNumeric will tell you that a string of numbers are numerical...but the add command will default to concatenate for an undeclared string.

Declare your variables!

Select as Best AnswerUndo Best Answer

user
animan1 (author)frollard2011-02-17
user
animan1 (author)aelias362011-02-17
user
jistjak (author)2012-01-28

This ALWAYS works for me you just have to make sure that you type a number in the box or else it will complain something about wrong data type.

x=inputbox("enter the first number")
y=inputbox("enter the second number")
x=x*1
y=y*1
answer=x + y


x and y are the input number variables change the name to whatever, the "x=x*1" and "y=y*1" will always turn a number in a string of numbers into a pure number. Hopidy Helpidy

Select as Best AnswerUndo Best Answer

user
Super_Nerd (author)2011-04-21

shouldn't it be c = a + b

Select as Best AnswerUndo Best Answer

user
animan1 (author)Super_Nerd2011-05-10

That was my problem, It set the number side-By-Side, not adding them

Select as Best AnswerUndo Best Answer

user
The Ideanator (author)2011-02-17

Magic, the answer is magic.

Select as Best AnswerUndo Best Answer

user
animan1 (author)The Ideanator2011-02-17

majic wont fix EVERYTHING

Select as Best AnswerUndo Best Answer

user
The Ideanator (author)animan12011-02-18

If magic gives witches their proverbial wings, one could certainly take a stab at VBScript with it.

Select as Best AnswerUndo Best Answer

user
animan1 (author)The Ideanator2011-02-18

exsplane to me, how would YOU use sleight of hand to fix a VBScript?

Select as Best AnswerUndo Best Answer

user
The Ideanator (author)animan12011-02-18

I'm talking about wizard magic, not magician magic.

Select as Best AnswerUndo Best Answer

user
animan1 (author)The Ideanator2011-02-23

like black magic? because thats is just evil

Select as Best AnswerUndo Best Answer