sean wrote:
HI,
I would like to know if I can some set a variable to return a single
value from a function using the set command. Is this possible?
Thanks in advance for your answer
Sean
SET test = ReturnValue(Opt ionID)
Unless you are intending to return an object from your function, do not use
the "SET" keyword.
Function ReturnValue(ByV al OptionID)
Set adoCmd = Server.CreateOb ject("ADODB.Com mand")
adoCmd.ActiveCo nnection = db_conn
adoCmd.CommandT ype = adCmdStoredProc
adoCmd.CommandT ext = "sp_findopt ion"
adoCmd.Paramete rs.Append adoCmd.CreatePa rameter("pOptio nID",adInteger )
adoCmd.Paramete rs("pOptionID" ) = OptionID
Set adoRec = adoCmd.Execute( )
OptionValue = adoRec(1)
adoRec.close Set
adoRec = Nothing
Set adoCmd = Nothing
End Function
This "function" does not return anything. To return a value from a function,
you assign the value you wish to return to the name of the function within
the function code. I'm guessing that you want to return the value contained
in the second field of the recordset returned by the stored procedure -
adoRec(1) - which makes me wonder why your stored procedure is returning
more than one field ...
Anyways, to return that value, do this instead:
ReturnValue = adoRec(1)
HTH,
Bob Barrows
PS. I would consider using an output parameter in your stored procedure to
return that single value. Using a recordset is overkill
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"