VB .NET Pointers

J

Jay B. Harlow [MVP - Outlook]

Danijel,
VB.NET does not support pointers, so there is no way to 'set pointer to
variable'.

What are you attempting to do, there may be a intrinsic .NET method to do
it.

Hope this helps
Jay
 
H

Herfried K. Wagner [MVP]

Hello,

Danijel Babic said:
Can you tell me how to set pointer to variable in VB.NET

Pointers (as known from C) are not supported in VB .NET. Maybe you want
to set a reference?!

Regards,
Herfried K. Wagner
 
D

Danijel Babic

Herfried K. Wagner said:
Hello,



Pointers (as known from C) are not supported in VB .NET. Maybe you want
to set a reference?!

Regards,
Herfried K. Wagner

Yes i want to set reference
 
C

CJ Taylor

Pass it into your fucntion or sub as

public function myFunction(ByRef myVariable as String) as Object

or

public sub mySub(ByRef myVariable as Object) as Object

don't take this literally, the only thing important is the ByRef statemenet.
 
H

Herfried K. Wagner [MVP]

Hello,

Danijel Babic said:
Pointers (as known from C) are not supported in VB .NET.
Maybe you want to set a reference?!
[...]
Yes i want to set reference

\\\
Dim x As New Bla()
Dim y As Bla = x ' Set a reference.
..
..
..
Public Class Bla
...
End Class
///

HTH,
Herfried K. Wagner
 
F

Fergus Cooney

Hi Danjiel,

What do you want to set a reference to, and to do what ?

Regards,
Fergus
 
D

Danijel Babic

I want to do something like this. I have array of user type variable and i
want to get and set data trough class



Public ReadOnly Property Data() As My_variable

Get

Return My_variable(number)

End Get

End Property

This example gets data from My_variable. When I type my_class.data. I get
complete list of all elements of My_variable. If i call my_class.data.name i
get my_variable(number).name which is what i want. The problem i to set data
to my_variable(number).name. If i try this:

set (byval value as my_variable) ' type of value must me my_variable

my_variable(number) = value

end set

my_class.data.name = "Something"

You see the problem. I can't pass string type and a get error

my_class.data.name is a value and therfore cannot be the target of an
assignment

Help me!
 
C

CJ Taylor

Could it be because your public property is set to READONLY?

Little things like that prevent you from writing to a variable.

By the way, I just read an page in Dan Appleman's book (VB Concepts and
Code) that explains why we don't use pointers in .NET (even though there is
Int32Ptr). The primary reason is to prevent corropution of memory (useful
tool) so that you don't overrun your memory buffer and corrupt other data.

All pointers to unmanged code are done within mangaged wrappers that take
care of things like this within the CLR.

Plus, he comments that pointers are some countries ways of punishing war
criminals.
 
F

Fergus Cooney

Hi again Danijel,

CJ is right about ReadOnly. Using it means that you can't have Set
within a Property.

From what I can understand of your code, you are protecting an array
with a Property. This should look more like:

Public Property Data (Index As Integer) As My_variable
Get
Return aMy_variable (Index)
End Get
Set
aMy_variable (Index) = Value
End Set
End Property

In use:
MyClass.Data (10) = MyVariableA
: : :
MyVariableB = MyClass.Data (10)

MyVariable is, of course, a variable of type My_variable.
The word Value in the Set represents whatever's on the right-hand side
of the assignment.

In your example you talk about assigning a string. This is impossible
because you have defined Data as working with values of type My_variable. If
strings are essential here, then either Data must be defined as of type
string, or your My_variable class must have a string member.

If we're not getting there, give us some of your actual code to look at.

Regards,
Fergus

ps. My_variable is a very bad name for a type/class. The name should reflect
what it means to you as a user of that class, not what it means to the
compiler.
 
D

Danijel Babic

This is some of the actual code

Private Index As Integer 'this i private variable for storing index

of array (Podatci)

Public Structure Struktura_Baze
Dim p1 As Integer
Dim p2 As String
Dim p3 As Double
End Structure

Private Podatci(100) As Struktura_Baze


I want to do this:

Class_name.data.p2 ="Something" 'Podatci(Index).p2 = "Something"
a = class_name.data.p3 'a = Podatci(Index).p3


how should look property of that class?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top