|
-
Apr 20th, 2006, 03:23 PM
#1
Thread Starter
Hyperactive Member
Can not divide in ASP!
This is driving me up the wall! I have been trying to get this ever so 'simple' code to work for the last hour!
All I want to do is divide a number by 2
this is what I have
VB Code:
<%
...
if rstFound.bof = false then found_rows = rstFound.Fields("foundrows").value
rstFound.Close
page_count = found_rows / 2
%>Found <%=page_count%>
this does not work!! found_rows is 44 so page count should be 22. If I remove the /2 it works fine, else I get a 500 error.
I've also tried * 0.5 and this does not work either
Help!
Last edited by Rick H; Apr 21st, 2006 at 12:56 AM.
-
Apr 20th, 2006, 04:28 PM
#2
Re: Can not divide in ASP!
Do you set a default value for found_rows?
Presumably you want to set it to 0 before the If.
-
Apr 20th, 2006, 04:55 PM
#3
Thread Starter
Hyperactive Member
Re: Can not divide in ASP!
Yup, the default for found_rows is zero.
What is interesting is this works:
VB Code:
if rstFound.bof = false then found_rows = rstFound.Fields("foundrows").value
rstFound.Close
found_rows=44
page_count = found_rows / 2
%>Found <%=page_count%>
and prints Found 22 on the page
however this
VB Code:
if rstFound.bof = false then found_rows = rstFound.Fields("foundrows").value
rstFound.Close
page_count = found_rows
%>Found <%=page_count%>
prints Found 44 inidicating that found_rows is 44? but does not work with the divide by 2, but if I manually set it to 44 (top example) then this works????
-
Apr 20th, 2006, 05:08 PM
#4
Thread Starter
Hyperactive Member
Re: Can not divide in ASP!
Fixed it! What a load of rubbish, only took me two hours
VB Code:
<%
...
if rstFound.bof = false then found_rows = cint(rstFound.Fields("foundrows").value)
rstFound.Close
page_count = found_rows / 2
%>Found <%=page_count%>
cint was the secret - god knows why
-
Apr 20th, 2006, 05:23 PM
#5
Re: Can not divide in ASP!
Presumably because the field foundrows is a String (or Text/Char) data type, rather than a numeric type.
As you have the answer, could you please do us a little favour, and mark this thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do this by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved".
-
Apr 21st, 2006, 12:59 AM
#6
Thread Starter
Hyperactive Member
Re: Can not divide in ASP!
Thats what I thought - originally I was trying to use Val() but this is not supported in ASP.
However Cint does not do string to integer conversions, it converts a numeric expression to an integer.
(see http://psacake.com/web/functions.asp?id=5)
-
Apr 21st, 2006, 01:53 AM
#7
Re: Can not divide in ASP!
 Originally Posted by Rick H
However Cint does not do string to integer conversions, it converts a numeric expression to an integer.
A string is a type of expression. A string such as "234" is a numeric one 
The following is perfectly valid in VB, and according to Microsoft should be exactly the same for VBScript (which is what ASP uses):
Have you checked what data type the "foundrows" field is?
-
Apr 21st, 2006, 02:37 AM
#8
Member
Re: Can not divide in ASP!
If you're ever unsure about what type of variable you're pulling back from things then you can try using typename to help you out, so:
msgbox Typename(found_rows)
in this case.
-
Apr 21st, 2006, 02:41 AM
#9
Thread Starter
Hyperactive Member
Re: Can not divide in ASP!
I'm not sure of the type as its returned by
Set rstFound = objConn.Execute("SELECT FOUND_ROWS() as foundrows")
after doing a "SELECT SQL_CALC_FOUND_ROWS ...." MYSQL query
-
Apr 21st, 2006, 02:43 AM
#10
Thread Starter
Hyperactive Member
Re: Can not divide in ASP!
Thanks l12ngo, I'll try that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|