473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Functions that return more than 1 value - Such a beast?

Hi,

I am creating a function for a payment gateway and wondered is there a
way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as
String AND Something else!

....
....
Return (Return Status - FAILED)
Return (Reason)
....
....
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
7 1638
Hi Daren

You could return a structure or a class object, and then fill in the
elements/properties accordingly.

HTH

Charles
"Daren Hawes" <ne********@webdesignmagic.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am creating a function for a payment gateway and wondered is there a
way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as
String AND Something else!

...
...
Return (Return Status - FAILED)
Return (Reason)
...
...
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Hi Daren,

I choise for the method from Charles, however you can even do it using a
simple arraylist.

Cor
Nov 20 '05 #3
You could also use ByRef variables.

eg.
Enum eReasons
Passed = 0
Failed = 1
Other =2
end Enum
function Payment(byval ccNumber as String, byval Amount as Integer, _
byref lReason as eReasons, byref sReason as String)

dim lReason as eReasons
dim sReason as String

Call Payment("12345678901234567890", 100, lReason, sReason)

However, as far as I know, this works only for value types.
Ofcourse, if you have multiple values, its better to go with a structure or
object as mentioned earlier..

Imran.
"Daren Hawes" <ne********@webdesignmagic.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am creating a function for a payment gateway and wondered is there a
way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as
String AND Something else!

...
...
Return (Return Status - FAILED)
Return (Reason)
...
...
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #4
> Daren Haweswrote:
Hi,

I am creating a function for a payment gateway and wondered is there a way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as String AND Something else!

....
....
Return (Return Status - FAILED)
Return (Reason)
....
....
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


I think a good rule of thumb is to use a class or structure as others
have indicated, if the data you want returned can be combined into
some intuitive entity. If not, then use multiple ByRef parameters.

Nov 20 '05 #5
Hi Daren,

Have you tried using ByRef arguments?

-Carl
"Daren Hawes" <ne********@webdesignmagic.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am creating a function for a payment gateway and wondered is there a
way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as
String AND Something else!

...
...
Return (Return Status - FAILED)
Return (Reason)
...
...
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6
Daren,
If I used ByRef parameters as the others suggest to return multiple values
from a method, I would seriously consider NOT making it a function, as this
can cause side effects that other programmers using your function are not
aware of.
Return (Return Status - FAILED) Suggests that you are "returning" an error or exception. If "return status
failed" is really an indication that the process can not be completed! I
would consider throwing an Exception at this point, as returning a "failed
status" can other other programmers using your function to easily ignore the
"failed status" and continue process, where as an Exception, they at least
need to wrap your function in a Try/Finally to ignore the Exception.

Hope this helps
Jay

"Daren Hawes" <ne********@webdesignmagic.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi,

I am creating a function for a payment gateway and wondered is there a
way for a function to return 2 or more values.

IE

Function Payment(ByVal ccNumber as String, Byval Amount as Integer) as
String AND Something else!

...
...
Return (Return Status - FAILED)
Return (Reason)
...
...
End Function
Or do I have to use properties?

Thx Daren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #7
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
I would consider throwing an Exception at this point, as returning a "failed status" can other other programmers using your function to easily ignore the "failed status" and continue process, where as an Exception, they at least
need to wrap your function in a Try/Finally to ignore the Exception.


I =definitely= second that motion! Troubleshooting is a whole lot easier
this way.

Best Regards,

Andy
Nov 20 '05 #8

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

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
7
by: BlueDragon | last post by:
The place where I work is moving to MS SQL Server from Lotus Notes. I have done a lot of coding in Lotus Notes, and have, I suppose, intermediate skills in basic SQL -- queries, insert, updates,...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
3
by: Joost van der Veen | last post by:
Hi, can somebody help me to translate this oracle function to a DB2 function; I've tried to do this but it didn't work. With this function i can separate one textfield with a delimmeter in...
9
by: billmiami2 | last post by:
I was playing around with the new SQL 2005 CLR functionality and remembered this discussion that I had with Erland Sommarskog concerning performance of scalar UDFs some time ago (See "Calling...
8
by: RN1 | last post by:
The book I am referring to learn ASP states the following about the Int & Fix VBScript Maths functions: ========================================= Both Int & Fix return the integer portion of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.