Want addition, not concatenation

In my VBScript I have the code line:

                    frm.Text3.value = frm.Text1.value + frm.Text2.value

If Text1.value = 7 and Text2.value = 8, then when the line is executed the entry in Text3 is "78" (concatenation), not 15 (addition).  How do I get the sum into Text3.

Note:  Text3 does display the correct mathematical result if the operator is *, - or / instead of +.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jmundsackConnect With a Mentor Commented:
^Not sure what parseInt() is--did you mean CInt()?

rlsokoloff, what's happening is VBScript is trying too hard to be helpful by making some assumptions about the data type your variables contain.  As you may or may not know, all variables in VBScript are "Variants" which are a special type of variable that include both the data, and the "subtype" of the data (i.e., the data type VB will treat the variant as).  When VBScript evaluates frm.Text1.value, it sees the result as a String, so the result is a Variant expression with a String subtype.  When using the + operator on Strings, the default behavior for VBScript is to concatenate.  So you, have to be heavy-handed about variables sometimes in VBScript, and force VBScript to see your expression as a specific Variant subtype--thus the use of CInt() or some other Cxxx() conversion function.

So, Morcalvin's response is correct in its intent--force the variables to be seen as integers--but I'm not quite sure what parseInt()--if CInt() works for you please give the points to Morcalvin because I'm sure that's what he/she meant.
frm.Text3.value = parseInt(frm.Text1.value) + parseInt(frm.Text2.value)
I mean CInt.  I was in javascript land(parseInt is the parse integer function in javascript)
rlsokoloffAuthor Commented:
Thank you,

I appreciate Morcalavin's response, but jmundsack provided the solution that I could actually implement.

I've used Cint() in Visual Basic, but didn't realize the various C-conversion functions were also part of the VBScripting engine.  Works fine!
rlsokoloffAuthor Commented:

Thanks again.  I'll remember that when working in javascript--with which I'm much less familiar.

All Courses

From novice to tech pro — start learning today.