Solved

simple OOP question

Posted on 2003-12-01
3
272 Views
Last Modified: 2013-11-25
Hi....

I have an OOP question.   Suppose I have created a class that loads and parses an XML file.  All of the xml data resides in arrays.  The class method that reads the data is private.  At runtime, I create an instance of my xml_parser class and populate the arrays.  I have also built another class that requires the use of these arrays.  How do I gain access to these variables?  Do I have to make my xml_parser method public?  When I create my other class instance and make a call to it....I tried passing the xml instance in to it.

ex...

xmlClass = new xml_parser()

myClass = new OtherClass(xmlClass)

how is this suppose to work?


thanks,

knoxxx
0
Comment
Question by:JohnnyKnoxville
[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
  • 2
3 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 9853891
You need to make the array's items publicly accessible via properties or the like, e.g.,


Public Property Get ArrayItem(ByVal Index As Long) As String
    ArrayItem = m_myprivatestringarray(Index)
End Property
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 9854832
Here is how to return an entire array with a property:

In Class1:
Private someArray() As String

Private Sub Class_Initialize()
    Dim a As Integer
   
    ' Put some simulated data in our array
    ReDim someArray(Int(Rnd * 24) + 1)
    For a = 0 To UBound(someArray)
        someArray(a) = Chr(Int((122 - 97 + 1) * Rnd + 97))
    Next a
End Sub

Property Get someArrayData() As Variant
    someArrayData = someArray
End Property

In Form1:
Private Sub Form_Load()
    Dim c As Class1
    Set c = New Class1
   
    Dim s() As String
    Dim a As Integer
   
    s = c.someArrayData
    For a = 0 To UBound(s)
        Debug.Print s(a)
    Next a
End Sub

Here is how to pass one class to another:

In Class2:
Private c As Class1

Public Property Set passClass1(ByRef newC As Class1)
    Set c = newC
End Property

Private Sub doSomethingWithClass1()
    Dim s() As String
    Dim a As Integer
   
    s = c.someArrayData
    For a = 0 To UBound(s)
        debugprint s(a)
    Next a
End Sub

Regards,

Idle_Mind
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9872549
Did we answer your question JohnnyKnoxville?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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