Nesting class

The following line in my program doesn't work :
        a.class2.pvar2 = TextBox1.Text
I don't have access to the property pvar2 in the sub or nested class.

in my form an simple button :
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As New Class1
        a.class2.pvar2 = TextBox1.Text
    End Sub

in have a simple class.vb
Public Class Class1
    Dim mvar1 As String

    Public Property pvar1() As String
        Get
            Return mvar1
        End Get
        Set(ByVal Value As String)
            mvar1 = Value
        End Set
    End Property

    Public Class class2
        Dim mvar2 As String

        Public Property pvar2() As String
            Get
                Return mvar2
            End Get
            Set(ByVal Value As String)
                mvar2 = Value
            End Set
        End Property

    End Class

End Class
dekeyzerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

123654789987Commented:
Try this
Dim a as new Class1.Class2
a.pvar2 = TextBox1.Text
0
armoghanCommented:
what is  a ?
class2 is a class, where is its object ?
0
armoghanCommented:
sorry i didnt see it

ok got it the property is not static,
so unless and untill an object is made of class2, as is described by 123654789987
or the property should be Static
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

armoghanCommented:
this class will work

Public Class Class1
    Dim mvar1 As String

    Public Property pvar1() As String
        Get
            Return mvar1
        End Get
        Set(ByVal Value As String)
            mvar1 = Value
        End Set
    End Property

    Public Class class2
        Shared mvar2 As String

        Public Shared Property pvar2() As String
            Get
                Return mvar2
            End Get
            Set(ByVal Value As String)
                mvar2 = Value
            End Set
        End Property

    End Class

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dekeyzerAuthor Commented:
Sorry but a new problem has arised when I tried with the "shared solution"

When I make two instances from the same class1 and i put different values in both instances then i have the same value in both.


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As New Class1
        Dim b As New Class1
        a.class2.pvar2 = "input A"
        b.class2.pvar2 = "input B"
        MessageBox.Show(a.class2.pvar2)   'the result is input B instead of input A
    End Sub
0
armoghanCommented:
Yes that is what the shared do..
It shares the varible in all objects.

Other way is that
do something like this in your Class1

Dim b As New Class2

and make a property to get b in class1

something like

 Public Property class2Property() As Class2
        Get
            Return b
        End Get
        Set(ByVal Value As String)
            b= Value
        End Set
    End Property


and so like this

a.class2Property.pvar2
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.