PDA

View Full Version : just a quick one !


steveg
11-06-2002, 01:57 PM
right, I need to round a number up. Ive looked in the help and it looks like I should be using the ceiling function but im not sure what happening because when I use the following command i just get a

"Type mismatch: 'ceiling'" error

the line generating this error is as follows

loop_around = ceiling(len(session_list2) / 250)

(session_list2 is just a character string about 300 characters)

any ideas ?

thanks

Steve.

whammy
11-06-2002, 11:54 PM
Hmm, I'm not aware of a ceiling function in VBScript (it looks like you're trying to use math.Ceiling() in JavaScript with VBScript? Although I haven't had the need to use that even, so I'm not sure if the syntax is right!).

<%
Function RoundUp(byVal num)
If IsNumeric(num) Then
If CInt(num) < num Then
RoundUp = CInt(num) + 1
Else
RoundUp = num
End If
End If
End Function

Response.Write(RoundUp(0) & "<br />" & vbCrLf)
Response.Write(RoundUp(.23) & "<br />" & vbCrLf)
Response.Write(RoundUp(1.00) & "<br />" & vbCrLf)
Response.Write(RoundUp(1.23) & "<br />" & vbCrLf)
%>


I think that's what you want, that way if there are any decimal places it will add one to the number. Not tested though, lemme know if it works (and I'm not smoking crack).

:)

BigDaddy
11-06-2002, 11:57 PM
Ceiling is also a function in SQL.

Here is a link that you'll find an explanation of it. I read it in an SQL book earlier today, but was not able to find it online. This explanation appears to be the same. If you're pulling data from a database, it would work using this function.

whammy
11-07-2002, 12:01 AM
Uh, I thought you were in class BigDaddy. You should pay attention to the teacher! That way you can help me in a few weeks if I need it when we're in the same class. ;)

BigDaddy
11-07-2002, 02:23 AM
Lol....the teacher is wandering off on a tangent right now....

"eef you want to..."

Nice guy, good teacher, but he tends to wander sometimes...

whammy
11-07-2002, 02:45 AM
He's probably trying to relate a slightly advanced concept and doesn't know exactly how to approach it with his students. I guess I'll find out in a little while. ;)

steveg
11-07-2002, 02:59 PM
Its going to be a couple of days before I get chance to test that code as Ive been pulled onto another job, however, it looks like it will do the job. The ceiling thing was off the MSDN librarys and seeing as Im really a Foxpro coder I know its a fox function but not sure why it was in the Vis Interdev docs.

Cheers pal

Ste...

whammy
11-07-2002, 07:32 PM
I did test it and it seems to work. It won't with negative numbers, but I'm sure you could figure out how to modify it for those if you needed to. Or I could real quick.

Funny thing is I looked at a bunch of complicated functions I found on the 'net for doing this, and I was like "Hmm. Why don't they just do this?" ;)