473,670 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning A Value from a single function

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)

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
Jul 19 '05 #1
2 4622
Have you tried it? Should be fine, although if you're just returning a
value from a recordset, which will be a string or a numeric, don't use SET.
Just do:

test = ReturnValue(Opt ionID)

Ray at home

"sean" <se********@sho psmart.com.au> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
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)

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

Jul 19 '05 #2
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"
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2952
by: Ken Godee | last post by:
module1 calls a function in module2 module2 starts a thread that calls a function in module3 and then returns to module1 thread finishes and I need the return value from the thread to use in module1 where program flow is continuing. err, I hope I explained that well enough?
7
1406
by: confusedcoder | last post by:
I found a strange piece of code that basically did the following: int doSomething(int& foo) { //manipulate the value of foo return foo; } int main(int argc, char* argv) {
41
3802
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x = rand(); y = rand();
10
3156
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences in levels of indirection, so I feel it must have something to do with the way I am representing the array in the call and the return. Below I have commented the problem parts. Thanks in advance for any help offered. Pete
17
3241
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
28
3680
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: void func (void) { } void func2 (void) {
0
4092
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
160
5829
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
5
2675
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return that structure, is this valid? As shown in the code below I am allocating the structure in the function and then returning the structure. I know if the structure contained only simple types (int, float) this will work without problems as you...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.