Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimals Needed

Status
Not open for further replies.

Elementary

Technical User
Dec 13, 2004
6
US
How and where in the code below can I force decimals to appear? Event_Category is a database field listing reading book levels such as 1.3 or 5.0 etc. The Event Category field in the Access database file does display the decimals, but when published, the drop-down-menu on the form displays some levels as whole numbers resulting in an inaccurate search for grade level 5 books, for example, which lists matcing books including levels 1.5, 2.5, etc. as well as level 5 books. I've attempted to add FormatNumber and ,1 as I've read online tips, but have been unsuccessful. A solution would be greatly appreciated. Please be specific. I'm very new to this. Thanks a million!
from Elementary

Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & Server.MapPath("db/events.mdb")
conn.Open DSNtemp%>
<% myquery="SELECT DISTINCT (Event_Category) FROM tblEvents ORDER BY Event_Category ASC"%>
<% Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open myquery, conn, 3, 3 %>
<P><font color="#000000"><B>List All Books In A Book Level</B></font></P>
<P>
<select class="select" name="FormCat" size="1">
<% Do While Not rs.EOF %>
<option name="FormCat">
<% = rs ("Event_Category") %>
<% rs.movenext %>
<% loop %>
<br>
<%rs.Close
Set rs = Nothing %>
 
Assuming that <%=rs("Event_Category")%> is where you print the actual number, replace it with this:
Code:
<%
If rs("Event_Category") = Int(rs("Event_Category")) Then
     Response.Write(Int(rs("Event_Category")) & ".0")
Else
     Response.Write(rs("Event_Category"))
End If
%>
Literally just padding a ".0" onto the end if it currently has no decimal part.
 
I made the changes you suggested but then the page would not display.
 
strEventCategory = parseInt("" & rs("Event_Category"))

function parseInt(str)
if isNumeric(str) then
parseInt = FormatNumber(str,0)
else
parseInt = 0
end if
end function
 
A couple of things. Do you get a specific error message? Also, just out of curiosity, what is the data type of the Event_Category field? Also, what was the specific syntax you used with the FormatNumber() function? These might help to track your problem down.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
In Internet Explorer, go to Tools->Options. Click the Advanced tab. Scroll down to "Show friendly http error messages" and uncheck it. Now try the page again. You'll get a much more specific error, including a line number. This is essential in debugging.

What is the precise error message now? Which line is throwing the error (not just the number, what is the code of the actual line an the lines surrounding it)?
 
After replacing the <%=rs("Event_Category")%> line with the ones offered in the first reply, I see: Microsoft VBScript compilation error '800a03f9'
Expected 'Then'
/elem_resources/booksearch/index.asp,line90
If rs("Event_Category") = Int(rs("Event_Category"))
---------------------------------------------------

In the Access database I set the data type to Number with Field Size of Decimal, Format to Fixed, Precision to 5, Scale to 1, and Decimal Places to 1.

Again, thank you for any assistance.
 
At the end of that line, you need to include Then. Like this:
Code:
If rs("Event_Category") = Int(rs("Event_Category")) [COLOR=red]then[/color]

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Now I see: Microsoft VBScript compilation error '800a0408'
Invalid character
/elem_resources/booksearch/index.asp,line 91
If rs("Event_Category") = Int(rs("Event_Category")) then
--------------------------------------------------------
 
I edited spaces I had and now have the page displaying, but with an error appearing in the Book Level field drop-down-menu. It says: Microsoft VBScript runtime error '800a01ca'Variable uses an Automation type not supported in VBScript/elem_resources/booksearch/index.asp, line 91" and the cell to the right of that is blacked out, where it originally has instructions for students.
I anxiously look forward to your assistance. Thanks for helping me progress.
 
What is line 91 on that page? That will help to track down your problem.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Line 91 appears to be: If rs("Event_Category") = Int(rs("Event_Category")) then
 
That probably tells us that rs("Event_Category") isn't a number. Is that possible? You may need to put
Code:
If IsNumeric(rs("Event_Category")) Then
     'Do the stuff you were trying here
Else
     'Deal with the fact that your data isn't a number here
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top