Solved

simple OOP question

Posted on 2003-12-01
3
273 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

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!

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 23 hours left to enroll

630 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