calculating numbers

1. Member
Join Date
Dec 1969
Posts
56

## calculating numbers

I&#039m a beginner with ASP. <BR><BR>form page:<BR><BR>&#060;form method="post" action="calculate.asp"&#062;<BR> &#060;input name="number1"&#062;<BR> +<BR>&#060;input name="number2"&#062;<BR> <BR><BR><BR> <BR> &#060;input type="submit" name="Calculate" value="Calculate"&#062;<BR>&#060;/form&#062;<BR><BR><BR>calculate.asp:<BR><BR>dim result, num1, num2<BR><BR>num1 = request("number1")<BR>num2 = request("number2")<BR><BR>result = number1 + number2<BR>%&#062;<BR><BR>&#060;%=result%&#062;<BR ><BR><BR><BR>So, if I enter numbers 4 and 6 and call calculate.asp, the result is 46 (surprise)<BR><BR>How I have to change the code that result is 10<BR><BR>Thank you

2. Member
Join Date
Dec 1969
Posts
56

## RE: calculating numbers

error! correction:<BR><BR>calculate.asp:<BR><BR>dim result, num1, num2<BR><BR>num1 = request("number1")<BR>num2 = request("number2")<BR><BR>result = num1 + num2<BR>%&#062;<BR><BR>&#060;%=result%&#062;<BR><B R><BR><BR>

3. samel Guest

## RE: calculating numbers

trying<BR><BR>num1 = request("number1")<BR>num2 = request("number2")<BR><BR>If IsNumeric(num1) Then<BR>&nbsp&nbspnum1 = CLng(num1)<BR>Else<BR>&nbsp&nbspnum1 = 0<BR>End If<BR><BR>If IsNumeric(num2) Then<BR>&nbsp&nbspnum2 = CLng(num2)<BR>Else<BR>&nbsp&nbspnum2 = 0<BR>End If<BR><BR>result = num1 + num2<BR><BR>

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

## Understanding what Request.Form gives you

Samel&#039s answer is right *if* the numbers will always be integers (CLng means "Convert to LoNG integer"). If they might have decimal points in them, use CDbl ("Convert to DouBLe").<BR><BR>Note that *all* values that come to ASP from a Request.Form or Request.QueryString are *ALWAYS* strings. That&#039s because there is no way in HTML to say that a given form element is a number or a date or something. To the browser and the HTML processor, *everything* is just a string. So if you know that the value needs to be a number (or date or currency) in your ASP page, use one of the CXxx functions to convert the string to the proper type. They are all listed under "functions" in the VBScript reference manual (click on "VBScript Reference" in the left panel here to get to the MSDN copy of the manual).<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
•