Numbers in String

1. Senior Member
Join Date
Dec 1969
Posts
105

## Numbers in String

If I multiply, I just get both strings attached to eah other (10+10=1010)<BR>I&#039;ve got the following code:<BR><BR>Dim N1<BR>Dim N2<BR>Dim N_een(110)<BR>Dim N_twee(110)<BR>Dim N(110)<BR>N1 = Request.Form("field1")<BR>N2 = Request.Form("field2")<BR><BR> N_een(0) = N1<BR> N_twee(0)= N2<BR> N(0) = N_een(0) + N_twee(0)<BR><BR><BR>In the form on the page before this one, I fill in the number 10 for both fields.<BR>N(0) will read 1010 and I want it to be 20!<BR>how&#039;s this possible?<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Multiply???

&#062; If I multiply, I just get both strings attached to eah other (10+10=1010)<BR><BR>Funny, first time I&#039;ve ever seen the + sign used to mean multiply.<BR><BR>Also funny: If you *had* used the normal multiply sign (*) it would have worked!<BR><BR>*ALL* values you get from Request.Form and Request.QueryString and Request.Cookies and Request.ServerVariables are *ALWAYS* strings!<BR><BR>So you were, effectively, doing<BR>&nbsp; &nbsp; "10" + "10"<BR>and that ends up asking the system to do string concatenation. Because the + operator is ambiguous (it means addition when using numbers but string concat when using strings...personally, I think this was an idiotic design decision).<BR><BR>So...<BR><BR>Use CINT or CLNG or CDBL to convert your strings to numbers. CINT and CLNG convert to integers (but CINT is limited to numbers from -32768 to +32767, so I recommend that you *never* use it!). CDBL allows most any number.<BR><BR>N1 = CDBL( Request("field1") )<BR>or<BR>N1 = CLNG( Request("field1") )<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
105

## RE: Multiply???

Ok, I&#039;m a dumb ***. Ofcourse I meant &#039;adding&#039;<BR>Thanks for your help, it works great now!

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sorry for teasing you...

...that was supposed to be just a little joke.<BR><BR>Ignore my inane humor and go with the answers &#060;sickly grin /&#062;.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•