Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Function in ASP 1

Status
Not open for further replies.

cyberprof

Programmer
Jun 10, 2003
229
0
0
GB
I've got a file called 'functions.asp' which contains the following function:

------------------------------------------------------------
Function GetSurname()

Set rstFunctions=Server.CreateObject("ADODB.Recordset")

SQuery = "SELECT * FROM tblNames WHERE ID = " & ??

rstFunctions.Open SQuery, Application("Connection"),3 ,3
Response.Write(rstFunctions("Surname"))
Set rstFunctions = Nothing

End Function
-----------------------------------------------------------
In my main asp page I'm using:
<!--#include file="../../functions/functions.asp"-->

How do I send a variable to the function to return the surname. The ?? needs to be the variable

Any help will be much appreciated.

Cheers J
 
Hi...
it's simple :
Code:
Function GetSurname(myVar)

    Set rstFunctions=Server.CreateObject("ADODB.Recordset")
    
    SQuery = "SELECT * FROM tblNames WHERE ID = " & myVar

    rstFunctions.Open SQuery, Application("Connection"),3 ,3
       GetSurname = rstFunctions("Surname")
    Set rstFunctions = Nothing

End Function
then, in your code, call the function like this :

Code:
  response.write GetSurname(10)
or
Code:
  MyScondVar = GetSurname(10)
which 10 is the ID which you want to pass to the function

----
Harsh words break no bones but they do break hearts.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top