473,395 Members | 1,521 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,395 software developers and data experts.

Why does VB.Net not support pointers?

1
VB.NET does not support pointers: Why?
Aug 24 '14 #1
2 2618
Luuk
1,047 Expert 1GB
A simple search finds a lot of pages on this topic, this is the first one:
How to do pointers in Visual Basic

and the second one:
Vb.net Pointers

Could you please give more details about your question after doing some research yourself?
Aug 24 '14 #2
Frinavale
9,735 Expert Mod 8TB
VB.NET is a bit weird when it comes to pointers because you wouldn't think that it makes use of pointers; however, pretty much everything in VB.NET is a pointer!


To quickly answer your question:
VB.NET does not support pointers: Why?

VB.NET does support pointers! In fact it almost exclusively uses pointers. It appears as if VB.NET doesn't support pointers because it is so transparent but it is very important to understand what VB.NET is doing for you! Otherwise you will be confused when you pass something ByVal and it is changed in the calling code unexpectedly.


Here's more of an explanation of what I'm talking about...


Let's say I have a class Person defined as such:
Expand|Select|Wrap|Line Numbers
  1. Public Class Person
  2.   Private _name As String
  3.  
  4.   Public ReadOnly Property Name As String
  5.    Get 
  6.      return _name
  7.    End Get
  8.    Set(ByVal value As String)
  9.      _name = value
  10.    End Set
  11.   End Property
  12.  
  13.   Public Sub New(ByVal n As String)
  14.     _name = n
  15.   End Sub
  16.  
  17. End Class
  18.  

And I create an instance to that person in my code as such:
Expand|Select|Wrap|Line Numbers
  1. Public Function Main(ByVal ParamArray Args() As String) As Integer
  2.   Dim p As New Person("Frinavale")
  3.  
  4.   Return 0
  5. End Function
  6.  
The variable p is a pointer to a memory location that is allocated to hold the information about the person.

If I pass this instance to a this ChangeName method
Expand|Select|Wrap|Line Numbers
  1. Public Function Main(ByVal ParamArray Args() As String) As Integer
  2.   Dim p As New Person("Frinavale")
  3.  
  4.   changePersonName(p, "Jenil")
  5.  
  6.   Return 0
  7. End Function
  8.  
  9. Private Sub changePersonName(ByRef personInChaneNameMethod As Person, ByVal newName as String)
  10.   personInChaneNameMethod.Name = newName
  11. End Sub
  12.  
The name for the variable p in the Main method will be changed to the new name.

But what is VERY important to know is that if we change the ByRef in the changePersonName method to be ByVal the same thing happens!!!

Why?

Because VB.NET only passes around pointers for anything that inherits from Object (which is pretty much everything).

If you pass a non-Object-inheriting item "ByVal" to the method, then the item in the calling code will not be changed (whereas if you pass this type "ByRef" it will be changed).

But if you pass an Object-inheriting item "ByVal" into a method it is still a pointer...so the item in the calling code Will be changed (in this case "ByRef" acts the same way).

To use pointers in VB.NET all you have to do is declare instances of Objects and use these variables


-Frinny
Sep 16 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
10
by: jbailo | last post by:
I've been working on my gcc/Gtk+ application and realized how much I need pointers. String manipulation in c is so beautiful and elegant and fast -- its way above all the dum-dum 'methods' of...
12
by: natkw1 | last post by:
Hi, I'm attempting to understand the use of pointers(at least grasp how pointers work). I've read the FAQ on http://www.eskimo.com/~scs/C-faq/s6.html on pointers and arrays but I'm still a bit...
3
by: Marc | last post by:
Does C# support pointers in any way, or are references in functions the only way to go?
11
by: Danijel Babic | last post by:
Hello! Can you tell me how to set pointer to variable in VB.NET Thank you!
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
4
by: Molina | last post by:
Hi !!! I have a VB.Net application that consumes an WebService. The problem is that the HTTP address works fine, but it will change to an HTTPS address, and it isn't working. The weird thing...
8
by: Divick | last post by:
Hi all, can somebody tell how much std::wstring is supported across different compilers on different platforms? AFAIK std::string is supported by almost all C++ compilers and almost all platforms,...
2
by: Vishnu Vardhan | last post by:
does .NET Language support pointers? if so where we can use and how we can use? and what are the ADO.NET Objects and Recordset is an object in ADO.NET?
28
by: Peter Olcott | last post by:
I want to make a generic interface between a scripting language and native code, the native code and the interpreter will both be written in C++. The interpreter will probably be implemented as a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.