ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old June 18th, 2003, 09:13 AM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
Post functions

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

Reply With Quote
  #2  
Old June 18th, 2003, 09:26 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,827 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 22 h 57 m 29 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
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.

Reply With Quote
  #3  
Old June 18th, 2003, 09:26 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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

Reply With Quote
  #4  
Old June 18th, 2003, 09:32 AM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
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

Reply With Quote
  #5  
Old June 18th, 2003, 09:47 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,827 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 22 h 57 m 29 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
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.

Reply With Quote
  #6  
Old June 18th, 2003, 10:01 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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

Reply With Quote
  #7  
Old June 20th, 2003, 03:23 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
figured out

i got er figured out, thanks for the help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > functions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway