473,399 Members | 3,656 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,399 software developers and data experts.

Using sub with byref Param or Function return value

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
5 4210
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
1
by: Dennis Powell | last post by:
Does anyone have a successful implementaion of the zlib.dll in VB. Net they can show me. I'm writting a class encaplsulating zlib functionality and I keep getting a System.NullReferenceException...
3
by: Paul | last post by:
I have been trying to code a callback in vb.net using the delegate method. I have successfully compiled the program and run it but after it accessess the copyfileex winapi method and then calls the...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
9
by: Samuel Shulman | last post by:
Hi I wander there is a way to return ByRef just like passing ByRef What I want to achieve is the following: Call a method that returns an object Use that call as an argument to a ByRef...
9
by: mtczx232 | last post by:
it's posible that Function return byref? what the syntax?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.