Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > ASP - Creating a custom function

Reply
Thread Tools

ASP - Creating a custom function

 
 
Noozer
Guest
Posts: n/a
 
      09-26-2004
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


 
Reply With Quote
 
 
 
 
Noozer
Guest
Posts: n/a
 
      09-26-2004
> 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.


 
Reply With Quote
 
 
 
 
Andrew Urquhart
Guest
Posts: n/a
 
      09-26-2004
*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)


news:microsoft.public.inetserver.asp.general

> 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...
--
Andrew Urquhart
- FAQ: http://www.html-faq.com/
- Archive: http://groups.google.com/groups?group=alt.html
- Contact me: http://andrewu.co.uk/contact/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating custom formatter function Garrett Cooper Python 1 02-16-2009 01:47 PM
creating custom options for custom widgets? Alexandre Guimond Python 0 03-22-2006 05:55 PM
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net Web Controls 0 06-01-2005 02:36 PM
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net 0 06-01-2005 02:36 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments