how to use a structure as property of a vb class??

altariamx2003
altariamx2003 used Ask the Experts™
on
Hi

I have this class
Public Class data
    Public Structure ParamCar
        Public Alfa As Double
        Public Eta As Double
        Public Mw7P As Double
        Public Z7P As Double
        Public Sg7P As Double
        Public Cf As Double
        Public Kw As Double
        Public Ja As Double
        Public Ya As Double
        Public Nscn As Integer
        Public Banderascn As Integer
        Public Metdesdob As Integer
        Public n As Integer
        Public metSg As Integer
        Public metTb As Integer
        Public metCriticas As Integer
        Public metTc As Integer
        Public metPc As Integer
        Public metomega As Integer
        Public ieq As Integer
    End Structure

    Private _mystructure As data.ParamCar
    Public Property mystructure() As data.ParamCar
        Get
            Return _mystructure
        End Get
        Set(ByVal value As data.ParamCar)
            _mystructure = value
        End Set
    End Property

    Private _name As String
    Public Property name() As String
        Get
            Return name
        End Get
        Set(ByVal value As String)
            dmyarray1 = value
        End Set
    End Property
End Class

Open in new window


-------------------------------------------------------------------------------------------------------------------------------
and when I tried to use it
        
     Dim example As New data()
        example.mystructure.Alfa = 34

Open in new window


vb show me the following error: "Expression is a value and therefore cannot be the target of an assignment"
 example-----------------------------------------------------------------------------------------------------------------
What Im doing wrong?

It is ok how I declare and use the structure as a property???

why vb show that error???
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Since you've used a structure, a COPY is made and returned from your property.  For it to work as you expect, you'll need to change from a structure to a CLASS.

Author

Commented:
mmm

something like this??
Public Class data
    Public class ParamCar
        Public Alfa As Double
        Public Eta As Double
        Public Mw7P As Double
        Public Z7P As Double
        Public Sg7P As Double
        Public Cf As Double
        Public Kw As Double
        Public Ja As Double
        Public Ya As Double
        Public Nscn As Integer
        Public Banderascn As Integer
        Public Metdesdob As Integer
        Public n As Integer
        Public metSg As Integer
        Public metTb As Integer
        Public metCriticas As Integer
        Public metTc As Integer
        Public metPc As Integer
        Public metomega As Integer
        Public ieq As Integer
    End class

    Private _mystructure As new data.ParamCar
    Public Property mystructure() As data.ParamCar
        Get
            Return _mystructure
        End Get
        Set(ByVal value As data.ParamCar)
            _mystructure = value
        End Set
    End Property

    Private _name As String
    Public Property name() As String
        Get
            Return name
        End Get
        Set(ByVal value As String)
            dmyarray1 = value
        End Set
    End Property
End Class

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
That's right.  Does it work now?
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Author

Commented:
yes its works

may I ask you another question???

another of the properties of my class are arrays, for example

    Private _myArray(,) As Double
    Public Property myArray() As Double(,)
        Get
            Return _myArray
        End Get
        Set(ByVal value As Double(,))
            _myArray = value
        End Set
    End Property

Open in new window


is there a way to change this property from two-dimentional array to a two-dimentional list?
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Hmm...you can try using a List(Of List(Of Double)).

Author

Commented:
hheee sorry bro could you help me with some example about how to use a two-dimensional list as a property in a class??

this is the first time that I tried to use list

Author

Commented:
nevermind I gonna keep with the property as array, the issue about how to change it to list it is just to know and be a better programmer

Author

Commented:
Thanks for your time Idle

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial