How to do that without pointers?

Joined
Jul 6, 2005
Messages
2
Reaction score
0
Hi all,
First of all I want to say that I come from C++, where pointers are "kings", but VB.NET don't have pointers :(
So I try some code like this but it dosn't work:
Code:
Public Class Class1
    Private objClass2 As Class2

    Public Sub setHash(ByRef hash As Class2)
        Me.objClass2 = hash
    End Sub

    Public Function getValue(ByVal name As String) As String
        Return Me.objClass2.getValue(name)
    End Function
End Class

Public Class Class2
    Private hastT As Hashtable

    Public Sub New()
        Me.hastT = New Hashtable
    End Sub

    Public Sub addNewValue(ByVal value As String, ByVal name As String)
        Me.hastT.Add(value, name)
    End Sub

    Public Function getValue(ByVal name As String) As String
        Return Me.hastT.Item(name)
    End Function
End Class
...
Code:
Dim objClass11 As New Class1
        Dim objClass12 As New Class1
        Dim objHast As New Class2

        objClass11.setHash(objHast)
        objClass12.setHash(objHast)

        objHast.addNewValue("1", "1")
        objHast.addNewValue("2", "2")

        Console.WriteLine(objClass11.getValue("1"))
        Console.WriteLine(objClass12.getValue("2"))

Is it posible to set a pointer to an object :confused:
 
Joined
Jul 6, 2005
Messages
2
Reaction score
0
Ups Sorry I found the problem :(

The ByRef is working OK.
I'm stupid :(

I change the variabilеs of key and values to the Hashtable Add Method

Public Sub addNewValue(ByVal value As String, ByVal name As String)
Me.hastT.Add(value, name)
End Sub

to this:

Public Sub addNewValue(ByVal value As String, ByVal name As String)
Me.hastT.Add(name, value)
End Sub

Sorry about that :(
Admin delete the post pls
 

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