M
Mark Raishbrook
Apologies in advance for what is a very simple question, but I just cannot
get my head around it. I have a public class Something with a public
structure T mapped to the local variable m_Test(). Whenever I try to set the
value of the property Test, I get the error "Expression is a value and
therefore cannot be the target of an assignment." Test code is below. Can
anyone tell me what I'm doing wrong?
Public Class Something
Public Structure T
Public a As Integer
Public b As Integer
End Structure
Private m_Test() As T
Private m_CurrentIndex As Integer
Public Property CurrentIndex() As Integer
Get
Return m_CurrentIndex
End Get
Set(ByVal Value As Integer)
m_CurrentIndex = Value
If Value > m_Test.GetLength(0) - 1 Then
ReDim Preserve m_Test(Value)
End If
End Set
End Property
Public Property Test() As T
Get
Return m_Test(m_CurrentIndex)
End Get
Set(ByVal Value As T)
m_Test(m_CurrentIndex).a = Value.a
m_Test(m_CurrentIndex).b = Value.b
End Set
End Property
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As Something
s.CurrentIndex = 1
s.Test.a = 2 '* Error!!!
End Sub
End Class
get my head around it. I have a public class Something with a public
structure T mapped to the local variable m_Test(). Whenever I try to set the
value of the property Test, I get the error "Expression is a value and
therefore cannot be the target of an assignment." Test code is below. Can
anyone tell me what I'm doing wrong?
Public Class Something
Public Structure T
Public a As Integer
Public b As Integer
End Structure
Private m_Test() As T
Private m_CurrentIndex As Integer
Public Property CurrentIndex() As Integer
Get
Return m_CurrentIndex
End Get
Set(ByVal Value As Integer)
m_CurrentIndex = Value
If Value > m_Test.GetLength(0) - 1 Then
ReDim Preserve m_Test(Value)
End If
End Set
End Property
Public Property Test() As T
Get
Return m_Test(m_CurrentIndex)
End Get
Set(ByVal Value As T)
m_Test(m_CurrentIndex).a = Value.a
m_Test(m_CurrentIndex).b = Value.b
End Set
End Property
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As Something
s.CurrentIndex = 1
s.Test.a = 2 '* Error!!!
End Sub
End Class