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

Using sub with byref Param or Function return value

P: n/a
Hi! I'm maybe from old school but, for me, whebn it's time to call a method
from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx
as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this
kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any
good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

The biggest thing is that if you are using a web service you can't call
ByRef. So the returnCode would never be valid in those situations. Also I
don't return error codes. An error is caught in the object and then either
handled or thrown back up to the calling routine. Returning error codes
forces you to test for errors at every single line of code that makes the
call. Using a centralized Error Handling system will make life a lot
easier. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Ghislain Tanguay" <gh****************************@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx
as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this
kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any
good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks

Nov 21 '05 #2

P: n/a
It is clearer as to what the intent of a function is, vs that of a sub with
a byref parameter. I have no idea why anyone would make it so difficult to
get a return value by using byref parameters with a sub, instead of
returning the result in a function.

Also, using subs you can't nest function calls - you have to have a separate
line of code for each function call, since you need to pass in the variable,
instead of just the result of a function call.

"Ghislain Tanguay" <gh****************************@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx
as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this
kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any
good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks

Nov 21 '05 #3

P: n/a
Both techniques have their own uses. You would a pass parameter ByRef if you
already have some value in it and want the procedure to return a modified
value. Another place where you would use ByRef variables is if you want to
return multiple values - since a function can return only one value, one
would usually change it to a sub and pass in the parameters as ByRef so you
have sort of 'multiple return values'. For most other purposes, ByVal would
be the way to go. Also, performance is not really an issue between the two,
AFAIK. So, that should definitely not be a criteria for using one over the
other. Another point to note is that we are talking about value types here.
For reference types, ByVal and ByRef behave differently.

http://msdn.microsoft.com/library/de...gmechanism.asp
hope that helps..
Imran.

"Ghislain Tanguay" <gh****************************@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx
as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this
kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any
good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks

Nov 21 '05 #4

P: n/a
Tks Ken,

Acutally I use a Try catch Error and throw a new SoapError.

But the point is, they use byref in webservice and it's ok too! There is no
problem using byref parameter with web service. The wsdl created will
transform those parameters
for an inout parameter.


"Ken Dopierala Jr." <kd*********@wi.rr.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

The biggest thing is that if you are using a web service you can't call
ByRef. So the returnCode would never be valid in those situations. Also I don't return error codes. An error is caught in the object and then either handled or thrown back up to the calling routine. Returning error codes
forces you to test for errors at every single line of code that makes the
call. Using a centralized Error Handling system will make life a lot
easier. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Ghislain Tanguay" <gh****************************@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi! I'm maybe from old school but, for me, whebn it's time to call a

method
from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks


Nov 21 '05 #5

P: n/a
For returning multiples values, I usually return an object, so my function
can do the job.

"Ghislain Tanguay" <gh****************************@hotmail.com> a écrit dans
le message de news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a
string or anything else I use a function. It's more verbose.

In my new company, much of my coworker works with Public sub ( byval Itemx
as integer, byref returnCode as Integer).

I don't understand why they use this kind of sub and i'm wondering if this
kind of sub take more time to response?

So, my question is, I have to debate this point tomorrow PM, is there any
good raison why we should prefer function to sub with a byref when byref
variable only seve to return a value?

Tks

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.