Solved

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

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

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now