472,341 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

byval & byref by god are drving me nuts

Is there any way to pass parameters to a function and simply know there will
get there without the silly (C like ) complexity of worring about byval and
or perhaps byref ?

(Why bother to have two languages in the first place now ....silliness ; OOP
taken to dysfunctional absurdity ! This idea is too counter productive to
last; MS , your king has no clothes on ...)
Nov 21 '05 #1
7 1770

"barrett bonden" <ar**********@yahoo.com> wrote in message
news:KQ*****************@fe09.lga...
Is there any way to pass parameters to a function and simply know there will get there without the silly (C like ) complexity of worring about byval and or perhaps byref ?

(Why bother to have two languages in the first place now ....silliness ; OOP taken to dysfunctional absurdity ! This idea is too counter productive to
last; MS , your king has no clothes on ...)


um, I understand that you are frustrated. However, I don't quite understand
the question.
What problem are you experiencing?
Are you asking what the real difference between ByVal and ByRef are?
Help me help you, provide more info.

Gerald
Nov 21 '05 #2

"barrett bonden" <ar**********@yahoo.com> wrote in message
news:KQ*****************@fe09.lga...
Is there any way to pass parameters to a function and simply know there
will
get there without the silly (C like ) complexity of worring about byval
and
or perhaps byref ?

(Why bother to have two languages in the first place now ....silliness ;
OOP
taken to dysfunctional absurdity ! This idea is too counter productive to
last; MS , your king has no clothes on ...)


Public Static Sub Main()
Dim byValParam As Integer = 12345
Dim byRefParam As Integer = 12345

ByValMethod(byValParam)
ByRefMethod(byRefParam)

Console.WriteLine("ByVal Value After ByValMethod: " & byValParam)
Console.WriteLine("ByRef Value After ByRefMethod: " & byRefParam)
End Sub

Public Sub ByValMethod(ByVal MyParam As Integer)
Console.WriteLine("ByValMethod MyParam Value: " & MyParam)
MyParam = 234
End Sub

Public Sub ByRefMethod(ByRef MyParam As Integer)
Console.WriteLine("ByRefMethod MyParam Value: " & MyParam)
MyParam = 234
End Sub
This will display:

ByValMethod MyParam Value: 12345
ByRefMethod MyParam Value: 12345
ByVal Value After ByValMethod: 12345
ByRef Value After ByRefMethod: 234
Follow it through and see the results yourself (Console application).

HOpe this helps ;)

Mythran
Nov 21 '05 #3
Barret,

In addition to the other answers

One of the big differences between a value and an object is the passing.

A ByVal passes with a value the value
A ByVal passes with an object his reference in the value
A ByRef passes (boxed) the reference in both situation in the value

I hope this helps?

Cor
Nov 21 '05 #4
>A ByRef passes (boxed) the reference in both situation in the value

ByRef doesn't imply boxing.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #5
Mattias,

I will investigate it better to explain it in a better way. Although it
explains in this way very easy.

Thanks.

Cor
Nov 21 '05 #6
Barrett,

"barrett bonden" <ar**********@yahoo.com> schrieb:
Is there any way to pass parameters to a function and simply know there
will
get there without the silly (C like ) complexity of worring about byval
and
or perhaps byref ?


In VB.NET, 'ByVal' is the default (opposed to VB6, where 'ByRef' was the
default), so you don't need to explicitly specify it. 'ByVal' and 'ByRef'
serve slightly different purposes for value types and reference types:

When passing a variable to a method in a 'ByVal' parameter, the variable's
content is duplicated and the copy is passed to the method. Altering the
parameter variable inside the method won't change the variable you passed to
the method. On the other hand, 'ByRef' will pass a "reference" to the
variable to the method, and thus assigning another value to the parameter
variable inside the method will affect the value of the variable passed to
the method:

\\\
Dim i As Integer = 2
DoSomething1(i)
MsgBox(CStr(i)) ' "2".
i = 2
DoSomething2(i)
MsgBox(CStr(i)) ' "3".
..
..
..
Private Sub DoSomething1(ByVal i As Integer)
i = i + 1
End Sub

Private Sub DoSomething2(ByRef i As Integer)
i = i + 1
End Sub
///

For reference types (classes) there is also a difference between 'ByVal' and
'ByRef'. By passing a variable to a parameter that is marked as 'ByVal', a
copy of the reference stored in the variable is created and this reference
is passed to the method. Thus you cannot change the reference the variable
you passed to the method is pointing to inside the method ('DoSomething1').
When passing the variable 'ByRef', the variable's reference is exposed to
the method directly and can be manipulated by the method, which means that
the method can let the variable you passed to the method point to another
object. The sample below will demonstrate this behavior:

\\\
Dim sb As New StringBuilder("Foo")
DoSomething1(sb)
MsgBox(sb.ToString()) ' "Foo".
sb = New StringBuilder("Foo")
DoSomething2(sb)
MsgBox(sb.ToString()) ' "Bla".
..
..
..
Private Sub DoSomething1(ByVal s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub

Private Sub DoSomething2(ByRef s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Very kind; many thanks to you all - I'll spend (waste in frustration ?)
some time working your kindly posted examples through ----I've spent 15
years writing (SMALL ! SHORT ! ) applications in Dbase, MS Access, etc, and
earning a good living at it - and you know what I'll say next; without ever
needing OOP or pointers or stacks, etc - I've approached OPP and VB Net a
number of times now and in good faith I still feel and must say: to me it
seems like nothing more than silly, massively excessive layers of
complexity that only get in the way of productive code -that OPP is a fad,
and will go the way of Deconstruction in lit or radical Behaviorism in
psychology or Marxism -

While I've got you guys; how much penetration is VB net making ? Anywhere
near as much as VB6? And is it successful - are (perhaps forgive me )
people really writing large applications in it ?

sorry for the rant, and thanks again -
"barrett bonden" <ar**********@yahoo.com> wrote in message
news:KQ*****************@fe09.lga...
Is there any way to pass parameters to a function and simply know there will get there without the silly (C like ) complexity of worring about byval and or perhaps byref ?

(Why bother to have two languages in the first place now ....silliness ; OOP taken to dysfunctional absurdity ! This idea is too counter productive to
last; MS , your king has no clothes on ...)

Nov 21 '05 #8

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

Similar topics

8
by: Sandy | last post by:
Hello! Help!!!! I have ten zillion books that attempt to describe the difference between ByVal and ByRef and none of them are clear to me. I...
3
by: Scott M. | last post by:
If I pass a reference type ByVal, am I making a copy of the object on the heap or am I making a copy of a pointer to the object on the heap? If I...
7
by: Hei | last post by:
Hi, i know the difference of ByRef and ByVal, in case if use byref or byval don't affect the result which one should prefer? (less memory use,...
4
by: Carlos Gomez | last post by:
In VB6 the default for passing variables was ByRef. It was faster and used less memory. Why did MS changed that? Are there any advantages using...
14
by: Robin Tucker | last post by:
Although I've been working on this project for 8 months now, I'm still not sure of the difference between ByVal and ByRef. As most objects in VB...
14
by: Niklas | last post by:
Hi What I have learned is that a variable is just a reference when dealing with Objects. Are you supposed to use ByVal or ByRef in functions? They...
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and...
2
by: Witold Iwaniec via .NET 247 | last post by:
It seems that when you pass an object to a function it is always passed by reference even if it is explicitly declared ByVal. Is it the behavior of...
8
by: Boni | last post by:
Dear all, I found out that I don' understand byVal/byRef in VB. There is a simple example: Why in the first test the result is 10,10 where in the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.