|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
||||
|
||||
|
wondering how to write a function in asp. i have a database that i'm querying, there are two different queries. the user submits a choice, and based on that choice the person selects it runs either one query, another query, or both queries. i don't want to have to write the output code four times with an if statement, i'd rather use a function call four times and write the code once. here is an example, i'm just wondering how to implement it.
if num=0 then sqlcode1="select something from anything" function(sqlcode1) else if num = 1 then sqlcode2="select nothing from nowhere" function(sqlcode2) else if num = 2 then sqlcode1="select something from anything" function(sqlcode1) sqlcode2="select nothing from nowhere" function(sqlcode2) else end if function(argument) rs = con.execute(argument) --loops and stuff to output select statement in a table end function show me the money ![]() |
|
#2
|
||||
|
||||
|
Are you using ASP or ASP.NET?
Typically (if you are using VB for the language) then it would be: Code:
Function function_name(argument As argument_type) As return_type
'function code
End Function
or for a sub (no value returned): Code:
Sub function_name(argument As argument_type)
'sub code
End Sub
I would recommend that you take a look at the microsoft site. Also, please use a more appropriate subject title next time. |
|
#3
|
|||
|
|||
|
Since we are
missing some *major* information, I'll have to ask some questions:
1) What are the types of queries that are going to be executed? Are they simple SELECT or you *might* have some UPDATE, INSERT, DELETE ??? 2) What is it that you want your *function* to return??? Because functions returns *things* as opposed to *procedure* Function MyFunction . . . MyFunction = "1" End Function Sub MySub ....code to execute but returns nothing... End Sub So do you want your function to return a recordset ??? But what if the SQL Statement is an UPDATE or INSERT then your function will not return a recordset right? Off the top of my head, all I see is something like this: Function ExecuteSQL(ByVal strSQL) .... Set ExecuteSQL = objConn.Execute strSQL End Function Or something like that... hope this helps! Sincerely Vlince |
|
#4
|
||||
|
||||
|
its just working with a select statement, so do i have to use a function or a sub or a procedure to output the query in a table? using just regular asp, not asp.net, and sorry about the title
|
|
#5
|
||||
|
||||
|
How to tell when to use a function or a sub is this:
If you want something returned to your code then use a function, if you just want something done but nothing returned then use a sub. |
|
#6
|
|||
|
|||
|
Onslaught's right
also here you say:
---BEGIN QUOTE--- ...so do i have to use a function or a sub or a procedure ... ---END QUOTE--- For the record and for futher use, a sub and a procedure are the *SAME* thing. Get the terminology straight, this will help you in the long run... Ok so you've said that you'll *only* be using SELECT statements. Then you say: ---BEGIN QUOTE--- ...to output the query in a table? ---END QUOTE--- Why don't *you* tell us exactly what you want your function to do? 1) Do you want it to INSERT the query you're passing as a parameter INTO your TABLE? OR 2) Do you want to EXECUTE the query that you're passing as a paramater against your TABLE? Assuming your answer is 2) then what is it you want your function to *RETURN* ? A) A recordset ? B) A nicely fromated html <table>...</table> What? Hope this helps! Sincerely Vlince |
|
#7
|
||||
|
||||
|
figured out
i got er figured out, thanks for the help
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > functions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|