[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Nesting class

Posted on 2004-10-27
6
Medium Priority
?
263 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:dekeyzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 1000 total points
ID: 12419865
Try this
Dim a as new Class1.Class2
a.pvar2 = TextBox1.Text
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12419926
what is  a ?
class2 is a class, where is its object ?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12419984
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Accepted Solution

by:
armoghan earned 1000 total points
ID: 12419994
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
 

Author Comment

by:dekeyzer
ID: 12420594
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12430154
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question