ASP - Creating a custom function

N

Noozer

Having a bad day here..

I need to create a custom function in an ASP page... (and please let me know
if there's a better group to ask in)

Since ASP does not have a MAIN funtion or LOAD event, code just starts at
the first ASP statement... so where do I define a custom function? How do I
return a value from a function?

This is what I'd like to add...

function toNum(val)
if ISNUMERIC(val) THEN
return cint(val)
else return 0
end if
end function
 
N

Noozer

I need to create a custom function in an ASP page... (and please let me
know
if there's a better group to ask in)

I forgot... It works like VB. This code seems to do the trick:

function toNum(val)
IF ISNUMERIC(val) THEN
toNum = cint(val)
else
toNum = 0
end if
end function

Just stuck it after the </BODY> tag - but I'm sure that there's a better
place to put it.
 
A

Andrew Urquhart

*Noozer* wrote in alt.html:

[Follow-up set to microsoft.public.inetserver.asp.general]
Having a bad day here..

I need to create a custom function in an ASP page... (and please let me know
if there's a better group to ask in)

Since ASP does not have a MAIN funtion

ASP is not a language, it's an API to the webserver (usually IIS).
or LOAD event, code just starts at the first ASP statement... so where
do I define a custom function?

It might seem obtuse, but you can define a function anywhere you like.
Although the usual method is to put functions into separate files and
include them at the top of the page using SSI syntax - the idea being to
attempt to separate script from markup for clarity and ease of
maintenance.
How do I return a value from a function?

It depends on the language you use under ASP (VBScript, JScript,
Perlscript, ...)
This is what I'd like to add...
function toNum(val)
if ISNUMERIC(val) THEN
return cint(val)
else return 0
end if
end function

Looks like VBScript and I'm not really familiar with it, instead here's
an approximation in JScript with some assumptions:

<%@language="JScript"%>
<%
function toNum(val) {
if (isNaN(val)) {
return 0;
}
else {
return Math.floor(val);
}
}
%>

....
<h1>Test</h1>
<p>My test result is <%=toNum(57.5)%></p>
....


Don't forget the follow-up...
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top