Calculation not working

J

JStrauss

Hello,
I am having a problem getting some code to calculate/work in an ASP page. In
the snippet below I am collecting some data (inthours1 and intrate1) and
then want to calculate a value (intsub1) to display on the page. If I set
intsub1 to a fixed value, the page displays correctly. If I try the
calculation listed below, I get a 500 internal server error on the page.
What am I doing wrong???

Thanks,
Joe

<%
Dim strSDate1, strEng1, intHours1, intRate1, intSub1

intHours1 = Trim(Request.Form("shours1"))
intRate1 = Trim(Request.Form("srate1"))

' Sub total buckets
intSub1 = inthours1 * intrate1
%>
<td><INPUT TYPE=TEXT NAME="SHours1" VALUE="" SIZE=10 MAXLENGTH=10></td>
<td><INPUT TYPE=TEXT NAME="SRate1" VALUE="" SIZE=12 MAXLENGTH=12></td>
<td><%= intSub1 %> </td>
 
B

Bob Barrows [MVP]

JStrauss said:
Hello,
I am having a problem getting some code to calculate/work in an ASP
page. In the snippet below I am collecting some data (inthours1 and
intrate1) and then want to calculate a value (intsub1) to display on
the page. If I set intsub1 to a fixed value, the page displays
correctly. If I try the calculation listed below, I get a 500
internal server error on the page. What am I doing wrong???
Hard to say without knowing what the real error is. Follow the steps shown
in this article to enable the real error to be displayed:
http://www.aspfaq.com/show.asp?id=2109
Thanks,
Joe

<%
Dim strSDate1, strEng1, intHours1, intRate1, intSub1

intHours1 = Trim(Request.Form("shours1"))
intRate1 = Trim(Request.Form("srate1"))

We (you) can't troubleshoot this calculation without knowing what values are
going into it. Use Response.Write to facilitate debugging:

Response.Write "intHours1 contains """ & intHours1 & """<BR>"
Response.Write "intRate1 contains """ & intRate1 & """<BR>"
Response.End

If this doesn't tell you what the problem is, show us the result.

Bob Barrows
 
J

JStrauss

Thanks for the tips. I am getting a type mismatch error, which I should be
able to track down. Thanks for the help.

Joe
 
L

Larry Bud

JStrauss said:
Hello,
I am having a problem getting some code to calculate/work in an ASP page. In
the snippet below I am collecting some data (inthours1 and intrate1) and
then want to calculate a value (intsub1) to display on the page. If I set
intsub1 to a fixed value, the page displays correctly. If I try the
calculation listed below, I get a 500 internal server error on the page.
What am I doing wrong???

Thanks,
Joe

<%
Dim strSDate1, strEng1, intHours1, intRate1, intSub1

intHours1 = Trim(Request.Form("shours1"))
intRate1 = Trim(Request.Form("srate1"))

' Sub total buckets
intSub1 = inthours1 * intrate1
%>
<td><INPUT TYPE=TEXT NAME="SHours1" VALUE="" SIZE=10 MAXLENGTH=10></td>
<td><INPUT TYPE=TEXT NAME="SRate1" VALUE="" SIZE=12 MAXLENGTH=12></td>
<td><%= intSub1 %> </td>

You have to convert the request.form to an int or float before you can
multiply it, don't you?

i.e.

intHours1=cint(trim(request.form("shours1"))

You should do some type checking before this.
 
A

Alex Kail

intHours1=cint(trim(request.form("shours1"))

Take this a step further and append a zero to the beginning. CInt will
throw an error if there is nothing in request.form("shours1"). So do
this:

intHours1 = cint("0" & trim(request.form("shours1"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top