Edinburgh Web Development

asp function gotcha

by Iain Wilson

8 November 2008

Here's a little problem we came across when maintaining a asp site written by another web development company. The original developer had written an asp function with a single parameter, and the function declaration was something like this:

function shownav(productid) .... .... .... end function

Calls to the function existed throughout the application, similar to this

.... shownav(pid) ...

We need to change the function to take two parameters and modified it accordingly:

function shownav(productid,subcat) .... .... .... end function

However, changing the function calls to include the second parameter didn't work:

.... shownav(pid,subid) ...

This generated the runtime error 'Cannot use parentheses when calling a Sub'. Of course we were not using a subroutine, but a function so it took a little time to figure it out. The solution relates to the feature of functions to return a value. This is done by assigning a variable to the function call (which the original code was not doing). So the following call code fixed the problem

.... x=shownav(pid,subid) ...

Liked this article? Please share it with your friends and colleagues.

comments powered by Disqus
Blot Design,
10 Colinton Road, Edinburgh, EH10 5DT
Terms, Cookies & Privacy