[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to pass a variable (string array) to nested classes?

Posted on 2013-06-06
9
Medium Priority
?
353 Views
Last Modified: 2013-06-13
I have an inner class that needs a variable from an upper class.  The variable is actually a string array.  I tried using Friend believing that it would make the variable available to the nested classes below the class that I used it in.  This did not work.  So I created a property to pass the variable but I am convinced that there must be a way to do this without writing a property to pass this variable for every nested class its needed.
0
Comment
Question by:NevSoFly
9 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39228250
Can you provide the structure of your parent and child classes?
0
 

Author Comment

by:NevSoFly
ID: 39229125
Thanks for your time.  I should have included this in my first post.  

Public Class OneClass
    Private _Equation As String
    Private equ() As String

    Public Function Start(ByVal Equation As String) As ArrayList
        _Equation = Equation
        equ = _Equation.Split("=") 'splits the equation into right and left expressions.
    End Function
End Class

Class AnotherClass
    Friend Property A As Array
        Get
            Return equ
        End Get
        Set(value As Array)
            equ = value
        End Set
    End Property

    Private ReadOnly Property B As String
        Get
            Return equ(0)
        End Get
    End Property

    Private ReadOnly Property C As String
        Get
            Return equ(1)
        End Get
    End Property

    Class Simplify
        Public ReadOnly Property D() As ArrayList
            Get
                Return equ(0)
            End Get
        End Property

        Public ReadOnly Property E() As ArrayList
            Get
                Return equ(1)
            End Get
        End Property
    End Class
End Class

Open in new window

0
 
LVL 10

Expert Comment

by:adriankohws
ID: 39229240
Will arraylist work for you?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:NevSoFly
ID: 39229273
It would work.  I just thought it was easier to do a simple array as it was all I needed.
0
 
LVL 10

Expert Comment

by:adriankohws
ID: 39229531
Actually, Arraylist are so simple and ease of use.

Dim ar as New ArrayList
ar.Add("1")
ar.Add("2")

Using a loop, you can load a list inside, and you can identify them by index.
0
 

Author Comment

by:NevSoFly
ID: 39229563
Exactly how would this help my original problem?
0
 

Author Comment

by:NevSoFly
ID: 39233432
Maybe it would help if I restated my desire.

I have an outer class with a variable (Private equ() as string) that I want to make available to inner classes (somestring = equ(0)).  I have tried private, public, shared and friend, all give me the error "'equ' is not declared. It may be inaccessible due to its protection level.".  

I have also included the  outer class when calling the variable (Outerclass.equ(0)).  This gives me the error "'equ' is not a member of 'WindowsApplication1.Expression'.".

Would a Structure work better?

I'm obviously missing something very basic.  Non of my searches has given me a glue as to how to fix it.

Please help.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 39239010
You can pass it into inner class in the constructor.
0
 

Author Closing Comment

by:NevSoFly
ID: 39245272
I would prefer not to do it that way but it could work for some instances.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 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