Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-06
9
Medium Priority
?
352 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

610 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