473,396 Members | 1,945 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.

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 1871

"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 have gathered that ByVal makes a copy and ByRef...
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 pass a string object (reference type) into a sub...
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, better performance ....issue) thx
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 ByVal over ByRef? (other than ByVal impeding you from...
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 are reference types, passing ByVal I've discovered...
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 produce the same result or have I missed...
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 byRef, and the results were slightly non-intuitive,...
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 VB.Net? Here is sample code from sample Asp.Net...
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 second 0,20. Thanks for your help. Boni Module...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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.