Solved

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

Posted on 2013-06-06
9
347 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
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!

 

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 500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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