By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
Hi Daren,

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

Cor
Nov 20 '05 #3

P: n/a
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

P: n/a
> 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

P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.