Search code examples
asp-classic

Classic ASP - Returning a value from a function


I have a function in Classic ASP which receives a value and in the function it runs through various CASE statements. What I want to do is return the value of that function into a variable that I can use.

For example

Function whichNumber(intNumber)
    SELECT CASE intNumber
        CASE 1
            whichNumber = "Yes"
        CASE 2
            whichNumber = "No"
    END SELECT 
END Function

When I call that function in the webpage via:

whichNumber(intNumberToFunction)

I am expecting then the variable "whichNumber" to be either "Yes" or "No". So the next line in the code I use:

strNumberText = whichNumber

However that results in the error:

Wrong number of arguments or invalid property assignment: 'whichNumber'

If I go back and in the function put the following at the end of the function:

Response.Write whichNumber

It correctly writes either "Yes" or "No" to the screen. Is there anyway to return the value of the function to a variable to use outside of the function?

Hopefully this makes sense! Reading around the web it seems it might not be possible to return a value from a function like this?


Solution

  • Do you not need to write

    strNumberText=whichNumber(intNumberToFunction)
    

    The error message is telling you that you have called the function without passing the parameter