can't assign value to me?

  • Thread starter Thread starter Terry Heath
  • Start date Start date
T

Terry Heath

Hi -

I've tried different ways to write to the variable me, but with no
luck. I've tried passing it to other methods as a byref parameter, and
even though it looks like it's written to the variable in the method,
when the method exits the variable is unchanged. Here is some code:

Module Module1

Sub Main()
Dim x As Integer = 3
Dim t As New test
Console.WriteLine(t.getS())
t.load()
Console.WriteLine(t.getS())
loadTest(t)
Console.WriteLine(t.getS())
Console.WriteLine("x = " & x)
intTest(x)
Console.WriteLine("x = " & x)
Console.ReadLine()
End Sub

Sub intTest(ByRef x As Integer)
x = 5
End Sub

Function getTest() As test
Dim t As New test("this one was made")
Return t
End Function

Function loadTest(ByRef t As test)
t = New test("load test succeeded.")
End Function
End Module

Class test
Private s As String

Sub New()
s = "not made"
End Sub

Sub New(ByVal s As String)
Me.s = s
End Sub

Sub New(ByVal t As test)
s = t.s
End Sub

Public ReadOnly Property getS() As String
Get
Return s
End Get
End Property

Public Sub load()
'Me = New test("")
load(Me)
End Sub

Private Sub load(ByRef t As test)
t = getTest()
't.s = "hi"
Console.WriteLine("in load")
End Sub
End Class

The external method (in the module) works fine, but the load doesn't
work in the class. I've tried making load a shared method, too, but
with no luck. Does anyone know of a workaround for this?

Thanks!
Terry
 
Terry Heath said:
I've tried different ways to write to the variable me, but with no
luck.

You cannot assign anything to 'Me'. 'Me' will return a reference to the
containing object, so it doesn't make sense to change this reference at all.
What exactly do you want to archieve?
 
Terry,

"Me" is used in a class to tell that it is the ("top") object from the
class.
(And therefore unchangeable because than it would become a complete
different object).

As sample.
\\\
dim ColorBleu as ColorMeBlue
ColorBlue.ColorControls(me)
'assuming it is a class inheriting from control as by instance a dialogform
///
\\\
Friend Class ColorMeBleu
Private Sub ColorControls(byval this as Control)
For each ctr in this.Control
ctr.backcolor = color.blue
Next
End sub
end Class
///
I hope this helps?

Cor
 
Back
Top